DEV Community

Cover image for ColdFusion Wrapper for Zint Barcode Generator
James Moberg
James Moberg

Posted on

ColdFusion Wrapper for Zint Barcode Generator

I referenced Zint Barcode Generator in a post from 2020 and included a very basic command line syntax for a QR code. Zint is able to generate 50 different barcode formats and I haven't found a java library that is capable of supporting the same formats or outputting files as BMP, EPS, GIF, PCX, TIF, EMF, PNG or SVG. (NOTE: I prefer to save as SVG and then use the static file when generating PDFs using WKHTMLTOPDF.)

There is a java port of Zint called OkapiBarcode. It's actively maintained, but looks like it requires more effort when building barcodes, requires the use of constants and doesn't appear to have any documentation beyond a couple of basic examples.

A project that I'm currently working on needs QR codes for the ticketing service. Normally, I'd use QRCode.js as it works with my CF_WKHTMLTOPDF custom tag if JavascriptDelay is configured for a second or two, but I'm not sure how reliable this would be when generating multiple pages that each contain a QR code. (NOTE: The built-in CFHTMLtoPDF tag doesn't support a javascript delay.)

In my quest to create a "more perfect DRY world" for myself, I decided to expand our existing logic that generates a command line string. Support for other features has been added and it triggers the executable and returns results. I've also made some tweaks to allow an entire configuration to be passed as a single options argument.

Here's sample CFML syntax to generate a basic QR code in SVG format. Enjoy!

options = [
    "filePath": "D:\www\this-is-a-test.svg"
    ,"data": "This is a test"
    ,"exePath": "C:\zint\zint.exe"
];
zintData = request.generateZint(options=options);

if (zintData.success){
    writeoutput('<img src="/this-is-a-test.svg" style="width:250px; height:auto;">');
} else {
    writedump(var=zintData.errors, label="Zint errors");
}

Enter fullscreen mode Exit fullscreen mode

Source Code

https://gist.github.com/JamoCA/fbbd2599102216448ada8e9f85d40b9c

Top comments (1)

Collapse
 
programmerraja profile image
Boopathi

This is a great solution for generating barcodes in ColdFusion! The ability to control the output format and integrate with WKHTMLTOPDF is incredibly useful. I'm definitely going to give this a try in my next project.