Chapter 6. Using DataBar Fonts in Crystal Reports

Adding barcodes to Crystal Reports is straightforward. The example included in the software was authored in Crystal Reports 9. The fonts and UFL are compatible with Crystal version 6 and above.

6.1. The User Function DLL

The software includes a file called U25MoroviaDataBar.dll, which is specially designed to provide Crystal Reports with DataBar encoding functions. If you installed the software using the installer we provided, the DLL can be found under c:\windows\system32 at default. When distributing your report, you can also copy it into the bin folder of Crystal Reports at c:\program files\common files\Crystal Decisions\version\bin. This file is not a COM DLL and does not require registration. After the DLL is copied, restart Crystal Reports.

Note

In the trial version, the DLL prompts a warning dialog when the encoder function is called. The full version does not have this limitation.

This DLL exports the following functions:

Table 6.1. List of Crystal Reports UFL Functions ( U25MoroviaDataBar.dll)

Function NameFont to UseComment
String Morovia_Code128_Uni (String)MRV DataBar 34XReturns the barcode string that becomes Code128 barcode for data DataToEncodeafter being formated with a Morovia DataBar Font.
String Morovia_EAN128_Uni (String)MRV DataBar 34XReturns the barcode string that becomes GS1-128 (UCC/EAN-128) barcode for data DataToEncodeafter being formated with a Morovia DataBar Font.
String Morovia_DataBar14 (String)MRV DataBar 34X [a]Returns the barcode string that becomes DataBar-14 barcode for data DataToEncodeafter being formated with a Morovia DataBar Font.
String Morovia_DataBarLimited (String)MRV DataBar 13XReturns the barcode string that becomes DataBar Limited barcode for data DataToEncodeafter being formated with a Morovia DataBar Font.
String Morovia_DataBarStacked (String)MRV DataBar 13XReturns the barcode string that becomes DataBar Stacked barcode for data DataToEncodeafter being formated with a Morovia DataBar Font.
String Morovia_DataBarStackedOmni (String)MRV DataBar 34XReturns the barcode string that becomes DataBar Stacked Omnidirectional barcode for data DataToEncodeafter being formated with a Morovia DataBar Font.
String Morovia_DataBarExpanded (String, Number)MRV DataBar 34XReturns the barcode string that becomes DataBar Expanded or DataBar Expanded Stacked barcode for data DataToEncodeafter being formated with a Morovia DataBar Font. The second parameter specifies the number of segments per row (0-22). DataBar Expanded is a subset of DataBar Expanded Stacked.
String Morovia_Mod10(String)N/AThis function calculates modulo 10 check digit based on the input data, and returns the original data with check digit appended. This function can be used to create full string for UPC-A, EAN-13 and GTIN numbers.

[a] To create a DataBar Truncated Barcode, use the same function but format the result with font MRV DataBar 13X.


6.2. Working with Crystal Reports

The screen shots in the following tutorial were taken in Crystal Reports 9. Interfaces in other versions may appear differently.

Assume that you have a database table with three fields: ID, GTIN and SerialNumber. You already put them into a report, and want to add a column to hold the DataBar14 barcodes for GTIN filed.

  1. First switch to design mode. In version 8, choose InsertFormula Field or in version 9 and above choose ReportFormula Workshop.

  2. Right click on Formula Fields and choose New.

  3. Give your formula field a name, in this example we will name it Morovia_DataBar. In versions 9 and above, you will be prompted to use the editor or the expert, choose Use Editor.

  4. In the Formula Editor, choose FunctionsAdditional Functionsmoroviadatabar(u25moroviadatabar.dll). Select Morovia_DataBar14 function.

    If you can not find the node moroviadatabar under Additional Functions, check if the dll is installed correctly.

  5. Place the cursor between the parentheses in the formula and select the field you wish to encode in the barcode from the Report Fields area in the Formula Editor. A correct formula will appear something like Morovia_DataBar14 ({TestData.GTIN}) where TestData.GTIN is the source field.

  6. The tables and fields should be visible above in your database connection. Choose SaveClose to close Formula Workshop.

  7. From the Field Explorer, drag the Morovia_DataBar14 Formula Field to the report.

  8. Choose FilePrint Preview. You should see a series of meaningless lower case letters and digits in the box. This is normal as the barcode string is completely difference from the data encoded in case of Databar.

  9. Switch back to design mode. Right click on the field and choose Format Field. Click on the Font tab, and choose the MRV DataBar 34X font. Set the font size to 12 points or to the size appropriate for your environment. To find out how to select the font and size, see Chapter 3, Choosing the Right Font and Size

  10. Drag the cursor to make the formula field big enough to contain the entire barcode. You may need to adjust both horizontally and vertically. Be sure to leave some spaces for quiet zone requirement.

  11. Run the Print Preview again. The barcode should come up. Print a page and scan the barcode to make sure that the font size is appropriate and the bounding rectangle is big enough to hold the whole barcode.

6.3. Special Handling: DataBar Expanded

Crystal Reports restricts length of strings returned from a UFL function to 254 characters. This limit is not a problem for encoder function except DataBarExpanded. When a large concatenated GS1-128 is encoded, the resulted string may exceed the limit.

When the barcode string exceeds the limit, our UFL will report an error message data is invalid, or too long. When this happens, you need to use the workaround outlined below.

Go back to the field definition and change it to the one below. Be sure to change the following variables: DataToEncode (data to be encoded) and SegmentsPerRow.

// Crystal Reports impose a constraint on UFL string length: max 254 characters.
// To get around this limit, use the code below
// This workaround require Crystal Report Version >= 9

StringVar DataToEncode := "(01)09501101420069(3922)995(3202)000100" +
        "(17)100101(422)123(21)123456";
// the number of segment per row
NumberVar SegmentsPerRow := 6; 

StringVar BarcodeString := "";

// First find out how many chunks required to get the whole barcode string
NumberVar chunks := Morovia_DataBarExpanded_Set(DataToEncode, SegmentsPerRow);

NumberVar i:=0;

// Loop until all the data is retrieved
For i :=1 To chunks Step 1 Do
(
    BarcodeString := BarcodeString + Morovia_DataBarExpanded_Get;
);

// Returns the complete string
BarcodeString; 

Note

The workaround requires Crystal Reports 9 and above because in earlier versions this 254 length limit also applies on formula fields.

The principle behind this workaround is to divide the barcode string into chunks. The first call Morovia_DataBarExpanded_Set returns the number of chunks needed, and in the subsequent loop Morovia_DataBarExpanded_Get retrieves a chunk of data each time. The data retrieved are combined into a string variable, which is returned as the value of the formula field.

6.4. Distributing UFL, Fonts with your report application

Once you finish the report design, you can distribute your report application with Crystal run time files, barcode fonts and the UFL library.

Note

Developer License is required to distribute font files and encoder UFL DLL outside your organization.

Two runtime files need to be included in your distribution package:

  1. Morovia DataBar Font Files. The font files are located C:\program files\morovia\DataBarFontware1.0, and should be copied to the target computer's fonts folder.

  2. DataBar Encoder UFL. This DLL is installed at C:\windows\system32 by default. In the target computer, it can be placed in the same location, or the bin folder of Crystal Reports at c:\program files\common files\Crystal Decisions\version\bin.