Chapter 7. Adding PDF417 Symbols to Crystal Reports

Adding PDF417 barcodes to Crystal Reports is straightforward. The example included in the software was authored in Crystal Reports 9.

Warning

Due to the length constraint imposed by Crystal Reports, the approach outlined in this chapter requires Crystal Reports version 9 and above, unless you are encoding fairly small amount of data.

7.1. User Function DLL

The UFL in version 5 is changed in order to work with 64-bit Crystal runtime. The new UFL is a COM-type dll and installed in the software's installation directory. Both 32-bit and 64-bit DLLs are included in the software.

PDF417 Fontware and Writer SDK 4 includes a type-25 UFL for Crystal Reports. Unfortunately type-25 UFL is not supported in 64-bit Crystal Reports. A new DLL is included in version 5 release as a result. However the function names are changed. If you have reports authored in version 4, you must change the function names. The previous version UFL is copied to the installation directory. However it is not visible to Crystal Reports. To allow old reports continue to work, copy the DLL to Windows system32 directory (on 64-bit Windows, the directory is C:\windows\SysWOW64, or to Crystal runtime directory (the one that has crpe32.dll.

This UFL exports two functions:

Table 7.1. List of Crystal Reports UFL Functions ( cruflPDF417V5.dll)

Function NameComment
Number PDF417EncodeSet (DataToEncode, numRows, numCols, securityLevel, aspectRatio, yHeight)Encodes the data into a full sized PDF417 barcodes with attributes specified. Returns the number of segments required for the data encoded.
Number PDF417CompactEncodeSet (DataToEncode, numRows, numCols, securityLevel, aspectRatio, yHeight)Encodes the data into a compact PDF417 barcodes with attributes specified. Returns the number of segments required for the data encoded.
String PDF417EncodeGet(chunkNo)Returns a segment of the result. Each segment consists of no more than 254 characters (the maximum number allowed by Crystal Reports).

The PDF417EncodeGet contains a single parameter which is the chunk index. The two encoder functions, PDF417EncodeSet and PDF417CompactEncodeSet have size parameters each. The first parameter is data encoded. The following six parameters are number of rows, number of columns, security level, aspect ratio and y-height [4]. The function returns a number, which indicates the number of subsequent calls to PDF417EncodeGet. Each call of PDF417EncodeGet retrieves a chunk of encoder results.

The following script demonstrates the basic flow to get it work in Crystal Reports:

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

StringVar DataToEncode := "Morovia PDF417 Fontware and Writer SDK " +
        "is a powerful software solution to create PDF417 symbols in Crystal Reports.";
          
NumberVar numRows := 0;  
NumberVar numCols := 3;
NumberVar securityLevel := 9;
NumberVar aspectRatio := 0.0;
// Note: 3.1 is for MRV PDF417N3 font.
// other font requires change of this parameter.  
NumberVar yHeight := 3.1;   

StringVar BarcodeString := "";

// First find out how many chunks required to get the whole barcode string
NumberVar chunks := PDF417EncodeSet(DataToEncode, 
          numRows, numCols, 
          securityLevel, aspectRatio, 
          yHeight);

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

// Returns the complete string
BarcodeString;

Because of the length restraint that UFL imposes on the string, it is not possible to complete in one UFL call. Instead, you prepare all parameters and call PDF417EncodeSet. This function calls encoder at the back end, and returns the number of chunks required. After that the program enters a loop that calls PDF417EncodeGet repeatedly until all result are retrieved and stored in BarcodeString.

7.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 several fields. You already put them into the report, and want to add a column to hold PDF417 barcode for ID field.

  1. First switch to design mode. 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_PDF417. 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 FunctionsVisual Basic UFLs (u2lcom.dll). You should see PDF417EncodeSet appears under. If not, the DLL is not installed properly.

  5. In the edit box below, copy and paste entire script in Section 7.1, “User Function DLL”. Make necessary changes. For example, you are likely to change the value of DataToEncode variable to one of your database field. Version, Error Correction Level can be changed in the code accordingly.

  6. Choose SaveClose to close Formula Workshop.

  7. From the Field Explorer, drag the Morovia_PDF417 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 PDF417 barcode.

  9. Switch back to design mode. Right click on the field and choose Format Field. Click on the Font tab, and choose the MRV PDF417 N3 font. Set the font size to 6 points or to the size appropriate for your environment.

  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.

Note

If you add barcodes to report using the trial version and subsequently upgrade to the full version, you need to refresh the report once. Otherwise the barcode will continue to be scrambled.

7.3. 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 run time files need to be included in your distribution package:

  1. Morovia PDF417 Font Files. The font files are located c:\windows\fonts, and should be copied to the target computer's fonts folder.

  2. PDF417 Encoder UFL. This DLL is installed at C:\Program Files (x86)\Morovia PDF417 Fonts & Encoder 5 by default. In the production computer, you can place this DLL anywhere. However, this is a COM DLL and requires registration. If you are deploying to a 64-bit Crystal Reports runtime, you need the 64-bit version of the DLL.



[4] Note: the y-height specified must match the font used, otherwise the aspect ratio will not be achieved correctly. To learn how these factors affect the final symbol size, see Chapter 2, Overview.