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. It is possible to create PDF417 Code symbols in earlier versions such as 8.5, but the solution is quite awkward. If you have such needs, write to for more information.

7.1. User Function DLL

The software includes a file called U25MoroviaPDF417FontEncoder4.dll, which is specially crafted to provide Crystal Reports with PDF417 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 two functions:

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

Function NameComment
Number Morovia_PDF417Encode_Set (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 Morovia_PDF417CompactEncode_Set (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 Morovia_PDF417_Get()Returns a segment of the result. Each segment consists of no more than 254 characters (the maximum number allowed by Crystal Reports).

The Morovia_PDF417_Get has no parameters. The two encoder functions, Morovia_PDF417Encode_Set and Morovia_PDF417CompactEncode_Set 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 Morovia_PDF417_Get. Each call of Morovia_PDF417_Get 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
// The forumula is written in Crystal Syntax.

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 PDF417 N3' font.
// other font requires change of this parameter. 
// See user manual for the y-height value of each font. 
NumberVar yHeight := 3.1;   

StringVar BarcodeString := "";

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

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

// 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 Morovia_PDF417Encode_Set. This function calls encoder at the back end, and returns the number of chunks required. After that the program enters a loop that calls Morovia_PDF417_Get 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 Functionsmoroviapdf417fontencoder4(U25MoroviaPDF417FontEncoder4.dll). You should see Morovia_PDF417Encode_Set 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 12 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:\program files\morovia\PDF417Fontware4, and should be copied to the target computer's fonts folder.

  2. PDF417 Encoder UFL. This DLL is installed at c:\windows\system32[5] 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.



[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.

[5] On 64-bit Windows, the directory is c:\windows\SysWOW64