Chapter 5. Adding QR Code Symbols to Crystal Reports

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

Note: the functions in this release are not backward compatible with old version QRCode Font & Writer SDK 1. You need to change the functions in order to use the new version API.

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 (127 digits or 77 alphanumeric).

5.1. User Function DLL

Crystal Reports extension DLL is included in the software (cruflQrcode5.dll), which provides QR code encoding functions. By default, this file can be found under the installation directory. This is a COM DLL - so you must register it if you move the file to another computer. This is typically done by running regsvr32 cruflQRCode5.dll command in a administrator console. In this release, both 32-bit and 64-bit versions are supplied. The 32-bit version is required to work with Crystal designer. The 64-bit is needed to work with 64-bit Crystal runtime. On 64-bit Windows, both DLLs are installed. [2]

This DLL exports three functions:

Table 5.1. List of Crystal Reports UFL Functions ( cruflQRCode5.dll)

Function NameComment
Number QRCodeEncodeSet (String, Number, Number)Encode the string specified with QRCode, and returns the number of chunks required to hold the barcode string result. The first parameter is data encoded, followed by minimum version required and error correction level.
Number MicroQRCodeEncodeSet (String, Number, Number)Encode the string specified with Micro QRCode, and returns the number of chunks required to hold the barcode string result. The first parameter is data encoded, followed by minimum version required and error correction level.
Number HIBCQRCodeEncodeSet (String, Number, Number)Encode the string specified with HIBC Qrcode, and returns the number of chunks required to hold the barcode string result. The first parameter is data encoded, followed by minimum version required and error correction level.
String QRCodeEncodeGet(Number)Returns a chunk of barcode string. Each chunk consists of no more than 254 characters (the maximum number allowed by Crystal Reports).
Number QRCodeGetParity (String)Calculate the parity acrossall the data. This is useful when you encode a series of symbols using Structural Append feature in the report.

Function QRCodeEncodeGet takes one argument which is the ordinal number of the chunk. By concatenating all the chunks together you get the full barcode string (which become a QRCode symbol after being formatted with the font).

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

//Morovia example formula to display qrcode barcodes
StringVar CompleteBarcodeString:="";
StringVar DataToEncode:= "data to encode enter here.";
NumberVar i:=0;
NumberVar Segments:=
QRCodeEncodeSet(DataToEncode, 0, 0);
For i:=0 to Segments Do
(
   CompleteBarcodeString := CompleteBarcodeString +
             QRCodeEncodeGet(i);
);
CompleteBarcodeString

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 QRCodeEncodeSet. This function calls encoder at the backend, and returns the number of chunks required. After that the program enters a loop that calls QRCodeEncodeGet repeatedly until all result are retrieved and stored in BarcodeString.

5.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 QRCode 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_QRCode. 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 QRCodeEncodeSet appears under. If not, the DLL was not installed properly.

  5. In the edit box below, copy and paste entire script in Table 5.1, “List of Crystal Reports UFL Functions ( cruflQRCode5.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 Morovia_QRCode 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 QRCode.

  9. Switch back to design mode. Right click on the field and choose Format Field. Click on the Font tab, and choose the MRV QRCode 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.

5.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 QRCode Font. The font files are located C:\windows\fonts\mrvqrcode.ttf, and should be copied to the target computer's fonts folder.

  2. QRCode Encoder UFL. This DLL is installed at C:\Program Files\Morovia QRCode Fonts & Encoder 5 by default. In the target computer, it can be placed 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.



[2] The 64-bit DLL is installed under C:\Program Files\Morovia QRCode Fonts & Encoder 5 directory, while the 32-bit DLL can be found under C:\Program Files (x86)\Morovia QRCode Fonts & Encoder 5.