Other Sites in the News
- November 13, 2024
- Types of Technology: A Complete Overview [2025] - Simplilearn
- October 23, 2024
- iPhone - Britannica
QR Code generation from OpenBD
There are blogs which discuss code generation using Adobe ColdFusion (ACF), and the Railo version of open-source CFML.
Here is a note to myself on QR Code generation using the zxing Java library with the OpenBD version of open-source CFML.
First, you'll need to place zxing resource Java (zxing_core.jar and zxing_javase.jar*) into the /lib folder of OpenBD's WEB-INF directory. Then restart your J2EE container (Tomcat in my case) so that the new classes are registered with OpenBD. After that, it's just a matter of using ColdFusion's built in hook to all things Java: the wonderful createObject() function.
Here's the starting snippets you'll need to generate QR Codes:
<!--- create the java object --->
<cfset BarcodeFormat = createObject('java','com.google.zxing.BarcodeFormat')>
<cfset writer = createObject('java','com.google.zxing.qrcode.QRCodeWriter').init()>
<!--- generate the QR matrix of origText --->
<cfset bitMatrix = writer.encode( origText, BarcodeFormat.QR_CODE, 200, 200 )>
<!--- convert matrix to an image --->
<cfset converter = createObject('java','com.google.zxing.client.j2se.MatrixToImageWriter')>
<cfset buff = converter.toBufferedImage( bitMatrix ) />
<cfset img = ImageNew( buff ) />
<!--- write image to disk --->
<cfset imageWrite(img,'#expandPath('./')#/foo.png','100',true) />
<cfoutput>
#origText#
<br />
<img src="./foo.png" />
</cfoutput>
This version just creates an actual image file and then displays it. In production, you may want to store the image in a database or just stream it straight to the browser behind a cfcontent tag, which qualifies your new method to be called directly from the src attribute of a HTML img tag!
* You can compile your own jar files using the zxing library source, or pull some compiled copies out of the example zip available at the Railo blog,