crystal-reports

How to use Interleaved 2 of 5 barcode font in Crystal Reports


I've downloaded the excellent Interleaved 2 of 5 font from https://grandzebu.net/informatique/codbar-en/code25I.htm and added it to Windows

But I need a formula to convert my data to Interleaved format since if I use it directly it will not add start and stop character and when I scan the barcode (after adding start and stop characters) it will not read the correct numbers. (If the data is "1234" the scanner will read "16171819", which corresponds to the ITF Barcode Character Set Chart)

I have found a solution to this and would like to document it in an answer for others to find. Please improve on the answer if possible or post another answer if you have a better solution.


Solution

  • Create a formula and add the following:

    StringVar Array patterns := [
          "!",chrW(34),"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","Ã","Ä","Å","Æ","Ç","È"
        ];
    StringVar input := {YOUR_DATA_STRING}; 
    StringVar barcode := "";
    
    //Pad with zero if the number of digits is odd
    If (Length(input) mod 2) = 1 Then
       input := "0" & input;
    
    Local NumberVar i;
    // Iterate through the input in pairs of digits and build the barcode string
    For i := 1 To Length(input) Step 2 Do (
       StringVar digitPair := Mid(input, i, 2);
       NumberVar pairIndex := Val(digitPair); // Converts the pair of digits to a number
       barcode := barcode + patterns[pairIndex + 1]; // Add 1 because arrays are 1-indexed in Crystal Reports
    );
        
    // Add start/stop characters
    barcode := "É" + barcode + "Ê";
    
    barcode
    

    Sidenote: The ITF-14 Character mapping is not standardized, so this mapping works for this font, it might differ slightly with other fonts, but it's the same principle. Just alter the pattern-array.