In a project I'm working on, I needed to generate a QR code and display it within an HTML file that is converted to a PDF using WKHTMLTOPDF. I didn't want to rely upon physical, statically-hosted SVG image files and wished to embed it. With WKTHMLTOPDF, I could use javascript to generate the QR code, but that requires adding a time delay and I didn't want to negatively impact processing time (even though WKHTMLTOPDF is faster than CFDocument.)
I already have a ColdFusion wrapper for Zint Barcode Generator function, so I just needed to write a CFML wrapper to:
- use generateZint() to create a temporary SVG file
- read the temp file data
- remove XML & HTML doctype headers
- modify the SVG XML source to "make it responsive"
- delete the temp file
Here it is. I hope that this helps some CFML developers.
UPDATE (8 Hours later)
I've updated the UDF so that it isn't dependent on the generateZint() UDF and so it outputs the SVG text directly to the console... thus skipping writing, reading & deleting. The process is now only:
- use zint.exe to capture SVG output
- remove XML & HTML doctype headers
I didn't notice much difference in terms of performance, but I consider it a win anytime I can reduce the amount of I/O calls to the file system.
Source Code
https://gist.github.com/JamoCA/fbbd2599102216448ada8e9f85d40b9c