BarCodeWiz Logo

GS1 Data Matrix in Crystal Reports

  • This tutorial shows how to add GS1 Data Matrix barcodes to your Crystal Reports.
  • See the video or follow the steps below.

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 GS1 Data Matrix 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 := "(01)09501101530003(17)140404(10)AB-123";

  // Minimum size of Data Matrix symbol.. Valid sizes are 1-30. 
  // Square sizes are 1-24 (size 1 equals 10x10 modules per side and size 24 equals 144x44).
  // Non-Square sizes are 25-30 (size 25 equals 8x18 modules, and size 30 equals 16x48).
  // Note: Size of symbol will automatically increase if too small for the data.
numberVar symbolSize := 1;              
  
  // Encoding mode for this Data Matrix symbol. Describes how to best encode the supplied text 
  // to achieve smallest symbol size.
  // Possible values are: Auto, Ascii, C40, Text, X12, Edifact, Base256
stringVar dataMatrixEncoding := "Auto";

  // 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
booleanVar allowSpecialChars := true; 

  // Determines whether the symbol is a regular DataMatrix or a GS1-DataMatrix barcode.
  // Set IsGS1 to false to create "regular" DataMatrix barcodes (default).
  // Set IsGS1 to true to create GS1-DataMatrix barcodes.
  // GS1-DataMatrix 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.
booleanVar isGs1 := true;            

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

  // Thickness of border around barcode, in number of modules.
  // If using a border, ensure quietZoneWidth is 1 or larger.
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;


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

fullBarcode;

 


  •  Make sure the isGs1 variable is set to true ( isGs1 := true; )

Step 4. Edit the formula

  •  Insert your own data into the field barcodeInput

Edit other variables.:

  •  symbolSize - Minimum size of Data Matrix symbol. Sizes vary from 1 to 30.  Square sizes are 1-24 (size 1 equals 10x10 modules per side and size 24 equals 144x44). Non-Square sizes are 25-30 (size 25 equals 8x18 modules, and size 30 equals 16x48).  Note: The size of the symbol will automatically increase if too small for the data.
  •  dataMatrixEncoding - Describes how to best encode the supplied text to achieve smallest symbol size. Possible values are Auto, Ascii, C40, Text, X12, Edifact, and Base256. 
  • allowSpecialChars - default set to true.  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 - default - 0 (no quiet zone). Thickness of quiet zone (space around barcode), in a number of modules.
    Note: Minimum quiet zone is 1 module. If you add a border (borderWidth > 0), ensure quietZoneWidth is 1 or larger.
  •  borderWidth - default - 0 (no border). Thickness of border around barcode, in a number of modules. If using a border, ensure quietZoneWidth is 1 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 - 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_DM
    NOTE:  For smaller barcodes, you can set the point size as low as 2pt
Change the font to BCW_DM and set the point size

  • Right-click and select Format Field...

  • Select Can Grow on the Common tab

Your report is ready

  • Click on Preview to see or print it.