Barcode Generation - FPDF

Asked

Viewed 572 times

-1

I am using classic Asp generating barcode in PDF.

I found little problem, in the function below calculates the barcode with one more digit,

If anyone can help find the error thank you.

I made a number of changes but I was unable to reach the result. The value that should be presented is : 481115243200001 however, present: 4811152432000001 a zero more.

I am using this routine for the standard 2 of 5

Sub fbarcode(Valor)
        Dim f, f1, f2, i
        Dim texto
        Dim p11
        p11=11
        Const fino = 0.4
        Const largo = 0.7
        Dim BarCodes(99)
if isempty(BarCodes(0)) then
    BarCodes(0) = "00110"
    BarCodes(1) = "10001"
    BarCodes(2) = "01001"
    BarCodes(3) = "11000"
    BarCodes(4) = "00101"
    BarCodes(5) = "10100"
    BarCodes(6) = "01100"
    BarCodes(7) = "00011"
    BarCodes(8) = "10010"
    BarCodes(9) = "01010"

    for f1 = 9 to 0 step -1
        for f2 = 9 to 0 Step -1
            f = f1 * 10 + f2
            texto = ""
            for i = 1 To 5
                texto = texto & mid(BarCodes(f1), i, 1) + mid(BarCodes(f2), i, 1)
            next
            BarCodes(f) = texto

        next
    next
    pdf.Text "30","225",texto
end if

xPos=55
p201=230
pdf.rect xPos, p201, fino, p11, "F"
xPos = xPos + fino + fino
pdf.rect xPos, p201, fino, p11, "F"
xpos = xpos + fino + fino


For n = 1 To Len(valor_barras) Step 2
    cASC = cint(Mid(valor_barras, n, 2))
    For i = 1 To 10 Step 2
        If Mid(BarCodes(cASC), i, 1) = "0" Then
            F = fino
        Else
            F = largo
        End If


        pdf.rect xpos, p201, F, p11, "F"
        xpos = xpos + F
        If Mid(BarCodes(cASC), i + 1, 1) = "0" Then
            xpos = xpos + fino
        Else
            xpos = xpos + largo
        End If

    Next
Next
pdf.Text "30","235",xpos

pdf.rect xpos, p201, largo, p11, "F"
xpos = xpos + fino + largo
pdf.rect xpos, p201, fino, p11, "F"


end Sub

3 answers

3

In the standard 2 of 5 the number must be even. So the function puts another zero

  • 1

    your answer is correct, but it would be good to edit everything in one post only. I would suggest deleting the other two, and pass here the content of both. Just click "edit" underneath them, and copy.

0

Sub fbarcode(valor_barras,xPos,p201)
    Dim f, f1, f2, i
    Dim texto
  Dim p11
  p11=12  'Altura do codigo de barras
    Const fino = 0.3
    Const largo = 0.6
    Dim BarCodes(99)
    if isempty(BarCodes(0)) then
        BarCodes(0) = "00110"
        BarCodes(1) = "10001"
        BarCodes(2) = "01001"
        BarCodes(3) = "11000"
        BarCodes(4) = "00101"
        BarCodes(5) = "10100"
        BarCodes(6) = "01100"
        BarCodes(7) = "00011"
        BarCodes(8) = "10010"
        BarCodes(9) = "01010"
        for f1 = 9 to 0 step -1
            for f2 = 9 to 0 Step -1
                f = f1 * 10 + f2
                texto = ""
                for i = 1 To 5
                    texto = texto & mid(BarCodes(f1), i, 1) + mid(BarCodes(f2), i, 1)
                next
                BarCodes(f) = texto
            next
        next
    end if

    'xPos=14
    'p201=233
    pdf.rect xPos, p201, fino, p11, "F"
    xPos = xPos + fino + fino
    pdf.rect xPos, p201, fino, p11, "F"
    xpos = xpos + fino + fino
    For n = 1 To Len(valor_barras) Step 2
        cASC = cint(Mid(valor_barras, n, 2))
        For i = 1 To 10 Step 2
            If Mid(BarCodes(cASC), i, 1) = "0" Then
                F = fino
            Else
                F = largo
            End If
            pdf.rect xpos, p201, F, p11, "F"
            xpos = xpos + F
            If Mid(BarCodes(cASC), i + 1, 1) = "0" Then
                xpos = xpos + fino
            Else
                xpos = xpos + largo
            End If
        Next
    Next

    pdf.rect xpos, p201, largo, p11, "F"
    xpos = xpos + fino + largo
    pdf.rect xpos, p201, fino, p11, "F"

end Sub

Function call :

Set pdf=CreateJsObject("FPDF")
pdf.CreatePDF()
pdf.SetPath("fpdf/")
pdf.LoadExtension("Codabar")
pdf.SetSubject("Results")
pdf.SetTitle("Results")
pdf.SetLeftMargin(35)
pdf.SetAutoPageBreak( 0)
pdf.Open()
---> fbarcode nome,Linha,coluna+2

pdf.close() 
filewrite=Server.MapPath("path/arq.pdf")
pdf.Output(filewrite)

0

<%
Sub fbarcode(valor_barras,xPos,p201)
    Dim f, f1, f2, i
    Dim texto
  Dim p11
  p11=12  'Altura do codigo de barras
    Const fino = 0.3
    Const largo = 0.6
    Dim BarCodes(99)
    if isempty(BarCodes(0)) then
        BarCodes(0) = "00110"
        BarCodes(1) = "10001"
        BarCodes(2) = "01001"
        BarCodes(3) = "11000"
        BarCodes(4) = "00101"
        BarCodes(5) = "10100"
        BarCodes(6) = "01100"
        BarCodes(7) = "00011"
        BarCodes(8) = "10010"
        BarCodes(9) = "01010"
        for f1 = 9 to 0 step -1
            for f2 = 9 to 0 Step -1
                f = f1 * 10 + f2
                texto = ""
                for i = 1 To 5
                    texto = texto & mid(BarCodes(f1), i, 1) + mid(BarCodes(f2), i, 1)
                next
                BarCodes(f) = texto
            next
        next
    end if

    'xPos=14
    'p201=233
    pdf.rect xPos, p201, fino, p11, "F"
    xPos = xPos + fino + fino
    pdf.rect xPos, p201, fino, p11, "F"
    xpos = xpos + fino + fino
    For n = 1 To Len(valor_barras) Step 2
        cASC = cint(Mid(valor_barras, n, 2))
        For i = 1 To 10 Step 2
            If Mid(BarCodes(cASC), i, 1) = "0" Then
                F = fino
            Else
                F = largo
            End If
            pdf.rect xpos, p201, F, p11, "F"
            xpos = xpos + F
            If Mid(BarCodes(cASC), i + 1, 1) = "0" Then
                xpos = xpos + fino
            Else
                xpos = xpos + largo
            End If
        Next
    Next

    pdf.rect xpos, p201, largo, p11, "F"
    xpos = xpos + fino + largo
    pdf.rect xpos, p201, fino, p11, "F"

end Sub
//chamada da função 
fbarcode nome,H,V+2     

Browser other questions tagged

You are not signed in. Login or sign up in order to post.