Enix
Enix

Reputation: 71

Generate barcode EAN13 in crystal report

I would like to generate barcode EAN13 from a string(For example: 1234567890123) or where can I free download for EAN13.ttf?

Upvotes: -4

Views: 10330

Answers (1)

anpadia
anpadia

Reputation: 131

This example worked for me:

http://www.aliquo.software/howto-generar-ean13-crystal-report/

To Print EAN13 with CrystalReport create a formula (sintaxis Basic):

enter image description here

With this code:

Function Generar_EAN13(Codigo As String) As String
' Esta función permite generar el código de barras para mostrarlo con la fuente EAN13.TTF
' - Parametros : código de 12 o 13 dígitos
' - Retorno: retorna una cadena que permite representar generar el código de barras con la fuente EAN13.TTF
'            retorna una cadena vacía si no se puede representar el código de barras

dim i,  first, checksum as number
dim code, code13 as string
dim tableA as boolean

' Evaluar los dígitos del código
If Len(Codigo) = 12 then
    code = Codigo
ElseIf Len(Codigo) = 13 then
    code = Left(Codigo,12)
Else
    code = ""
end If

' VerIficar los dígitos del código
For i = 1 To LEN(code)
    If Asc(Mid(code, i, 1)) < 48 Or Asc(Mid(code, i, 1)) > 57 Then
        code = ""
        Exit For
    End If
Next

' Chequea los 12 dígitos y cálcula el digito de control
If Len(code) = 12 Then
    For i = 12 To 1 Step -2
        checksum = checksum + Val(Mid(code, i, 1))
    Next
    checksum = checksum * 3
    For i = 11 To 1 Step -2
        checksum = checksum + Val(Mid(code, i, 1))
    Next
    code = code & ToText((10 - checksum Mod 10) Mod 10,0)

    ' Si el código inicial tenía 13 dígitos comprueba si el nuevo código generado
    ' es igual y en caso contrario no se generar ningún código
    If Len(Codigo)=13 and Codigo<>code then
        code = ""
    end If
End If

' Chequea los 13 dígitos
If Len(code) = 13 Then
    ' Los primeros 2 dígitos que suelen corresponder al código del país
    code13 = Left(code, 1) & Chr(65 + Val(Mid(code, 2, 1)))
    first = Val(Left(code, 1))

    ' Generar los códigos del primer bloque de dígitos
    For i = 3 To 7
        tableA = False
        Select Case i
            Case 3
                Select Case first
                    Case 0 To 3
                        tableA = True
                End Select
            Case 4
                Select Case first
                    Case 0, 4, 7, 8
                        tableA = True
                End Select
            Case 5
                Select Case first
                    Case 0, 1, 4, 5, 9                 
                        tableA = True
                End Select
            Case 6
                Select Case first
                    Case 0, 2, 5, 6, 7
                        tableA = True
                End Select
            Case 7
                Select Case first
                    Case 0, 3, 6, 8, 9
                        tableA = True
                End Select
        End Select
        If tableA Then
            code13 = code13 & Chr(65 + Val(Mid(code, i, 1)))
        Else
            code13 = code13 & Chr(75 + Val(Mid(code, i, 1)))
        End If
    Next

    ' Añadir el separador de los bloques
    code13 = code13 & "*"

    ' Generar los códigos del segundo bloque de dígitos
    For i = 8 To 13
        code13 = code13 & Chr(97 + Val(Mid(code, i, 1)))
    Next

    ' Añadir la marca final
    code13 = code13 & "+"
End If

Generar_EAN13=code13

End Function

Install this font (EAN13.ttf) in your PC:

http://download.aliquosoftware.net/documentation/ean13.ttf

Or alternative from here:

http://grandzebu.net/informatique/codbar/ean13.ttf

Add a text formula with the call. For example:

enter image description here

Configure it with the font installed:

enter image description here

Then, you will see the EAN 13 code:

enter image description here

For more information, you can see this web:

http://grandzebu.net/informatique/codbar-en/ean13.htm

Upvotes: 2

Related Questions