BarCodeWiz Logo

GS1 QR Code in Crystal Reports made using BarCodeWiz QR Code Fonts

  • This tutorial shows how to add GS1 Data Matrix barcodes to your Crystal Reports.

Step 1. Add a new formula

  • In the Field Explorer, right-click Formula Fields and click New...

  • Enter a name for the new formula

Step 2. Verify the presence of our GS1 QR Code functions

  • Open Formula Editor. Ensure the functions are installed. May be listed under one of these three locations:
    Functions > Additional Functions
    Functions > Additional Functions > Visual Basic UFLs (u2lcom.dll)
    Functions > Additional Functions > COM and .NET UFLs (u212com.dll)
  •  If missing, install the User Function Library

Step 3. Copy the formula text

  •  Copy the contents of this text into the Formula Editor:
  // This is the text you wish to encode. Replace "Hello..." with your own data.
  // For example: stringVar barcodeInput := {my_data_table.item_text}; 
  // 
  // If your data is a number or date, it must be converted to string using the ToText() function.
  // For example: local stringVar barcodeInput := ToText( {my_data_table.item_text}, 0, ""); 
local stringVar barcodeInput := "Hello World مرحبا بالعالم Witaj świecie";

 // Minimum size of QR Code symbol.
 // Valid sizes are 1-40, where size 1 equals 21x21 modules per side and size 40 equals 177x177.
 // Note: Size of symbol will automatically increase if too small for the data.
local numberVar symbolSize := 1;            
	  
 // Error correction level allows a partially damaged barcode to be scanned successfully.
 // Valid values are 1-4, representing levels of L, M, Q, and H.
local numberVar errorCorrectionLevel := 1;

 // Allows input of special characters in format ^000 where 000 is decimal ASCII code. 
 // For example, ABC^009123^013^010 encodes "ABC[TAB]123[CARRIAGE RETURN][LINE FEED]".
 // To encode the actual caret ^, enter it twice: ^^
 // To encode FNC1, enter: ^F1
local booleanVar allowSpecialChars := true;

 // Determines what type of QR Code barcode to create.
 // Set fnc1Mode to 0 to create "regular" QR Code barcodes (default)
 // Set fnc1Mode to 1 to create GS1-QR barcodes.
 // GS1-QR barcodes require input to be in the format: "(NN)XXXXXX(NN)XXXXXXXXX",
 // where NN is a 2, 3, or 4-digit AI and XXXXXX is alphanumeric data to be encoded.
local numberVar fnc1Mode := 0; 

 // Thickness of quiet zone (space around barcode), in number of modules.
 // Note: Minimum quiet zone in QR Code is 4 modules. 
 // If you add a border (borderWidth > 0), ensure quietZoneWidth is 4 or larger.
 // Default value is 0 (no quiet zone)
local numberVar quietZoneWidth := 0; 

 // Thickness of border around barcode, in number of modules.
 // If using a border, ensure quietZoneWidth is 4 or larger.
local numberVar borderWidth := 0; 

 // Character encoding of your data input.
 // For example: UTF-8 | UTF-16 | ISO-8859-1 | ISO-8859-3 | ISO-2022-JP-2 
 // This setting should be set to UTF-16 (Unicode) for Crystal Reports 9 and newer
 // Crystal Reports automatically converts all input (from database fields, strings, etc) into UTF-16.
local stringVar characterInputEncoding := "UTF-16";

 // Character encoding for data encoded in the QR Code symbol. 
 // The recommended setting is UTF-8, which is the default for the majority of barcode scanners.
 // If you change the setting, be sure the scanner understands it.
local stringVar characterOutputEncoding := "UTF-8";


local numberVar strLen := Length(barcodeInput);
local stringVar hex;
local stringVar xvals := "0123456789ABCDEF";
local numberVar i;
For i := 1 to strLen Do
(
    local numberVar num := AscW(Mid(barcodeInput, i, 1));
    local numberVar first := Remainder( num,  256);
    local numberVar sec := Int( num / 256);

    hex := hex + Mid(xvals, Int(first/16) + 1, 1) + 
                 Mid(xvals, Remainder(first, 16) + 1, 1) + 
                 Mid(xvals, Int(sec/16) + 1, 1) + 
                 Mid(xvals, Remainder(sec, 16) + 1, 1);
);

local stringVar fullBarcode := "";
local numberVar partNumber := 0;

local stringVar result;
Do 
(
    result := QrCodeEncodeFromHex(partNumber, hex, symbolSize, errorCorrectionLevel, 
                                    allowSpecialChars, fnc1Mode, quietZoneWidth, borderWidth, 
                                    characterInputEncoding, characterOutputEncoding);
    fullBarcode := fullBarcode + result;
    partNumber := partNumber + 1;
)
While result <> "";

fullBarcode;

 

 

 


  • Make sure the fnc1Mode variable is set to true (fnc1Mode := 1)

Step 4. Edit the formula

Insert your data into the field barcodeInput

We used these GS1 formatted values:

local stringVar barcodeInput := "(01)09501101530003(17)240404(10)AB-123";

 


Edit other variables.:

  • symbolSize - Minimum size of QR Code symbol. Valid sizes are 1-40, where size 1 equals 21x21 modules per side and size 40 equals 177x177.
    Note: Size of symbol will automatically increase if too small for the data.
  •  errorCorrectionLevel - Error correction level allows a partially damaged barcode to be scanned successfully.
    Valid values are 1-4, representing levels of L, M, Q, and H.
  •  allowSpecialChars - Allows input of special characters in format ^000 where 000 is decimal ASCII code. For example, ABC^009123^013^010 encodes "ABC[TAB]123[CARRIAGE RETURN][LINE FEED]".
    To encode the actual caret ^, enter it twice: ^^
    To encode FNC1, enter: ^F1
  •  quietZoneWidth - Thickness of quiet zone (space around barcode), in number of modules.
    Note: Minimum quiet zone in QR Code is 4 modules. 
    If you add a border (borderWidth > 0), ensure quietZoneWidth is 4 or larger. Default value is 0 (no quiet zone).
  •  borderWidth - Thickness of border around barcode, in number of modules.  If using a border, ensure quietZoneWidth is 4 or larger.
  •  characterInputEncoding - Character encoding of your data input.
    For example: UTF-8 | UTF-16 | ISO-8859-1 | ISO-8859-3 | ISO-2022-JP-2 
    This setting should be set to UTF-16 (Unicode) for Crystal Reports 9 and newer
    Crystal Reports automatically converts all input (from database fields, strings, etc) into UTF-16.
  • characterOutputEncoding - Character encoding for data encoded in the QR Code symbol. 
    The recommended setting is UTF-8, which is the default for the majority of barcode scanners.
    If you change the setting, be sure the scanner understands it.

  • Click Save and Close

Step 5. Add your barcode to the report

  • Drag the formula from Field Explorer to the report

Step 6. Edit the text field

  • Change the font to BCW_QR

    NOTE:  For smaller barcodes, you can set the point size as low as 2pt

  • Right-click and select Format Field...

  • Select Can Grow on the Common tab
  • Clik OK

Your report is ready

  • Click on Preview to see or print it.