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.



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