Create QR Barcode with ColdFusion and Zxing

Too often I write “It was too easy with ColdFusion”, it’s becoming a cliché now. Making a QR barcode with ColdFusion was extremely easy too, specially when someone else have already blog about it. I had nothing to dig out, nothing to investigate or haven’t had the need for countless cups of coffee. I wish everything works like that.

This uses Google zxing java library. I put necessary classes into a single jar file and you can download the example below. It uses JavaLoader to load to the Java classes. But if you are happily floating on Railo, you know you don’t have to use JavaLoader. Railo is Cool.

Railo Code (Without JavaLoader)

   1: <cfset corefile     = ExpandPath('core.jar')>
   2: <cfset BarcodeFormat    = createObject('java','com.google.zxing.BarcodeFormat',corefile)>
   3: <cfset QRCodeWriter    = createObject('java','com.google.zxing.qrcode.QRCodeWriter',corefile).init() />
   4: <cfset MatrixToImageWriter    = createObject('java','com.google.zxing.client.j2se.MatrixToImageWriter',corefile)>
   5: <cfset QRcode     = QRCodeWriter.encode( 'http://cflove.org', BarcodeFormat.QR_CODE, 100, 100 )>
   6: <cfset image     = ImageNew( MatrixToImageWriter.toBufferedImage( QRcode ) )/>
   7: <cfimage action="writeToBrowser" source="#image#" format="png">
Show/Hide Line Numbers . Full Screen . Plain

With JavaLoader

   1: <cfset paths    = arrayNew(1)>
   2: <cfset paths[1]    = expandPath("core.jar")>
   3: <cfset loader    = createObject("component", "javaloader.JavaLoader").init(paths)>
   4: <cfset BarcodeFormat    = loader.create('com.google.zxing.BarcodeFormat')>
   5: <cfset QRCodeWriter    = loader.create('com.google.zxing.qrcode.QRCodeWriter').init()>
   6: <cfset MatrixToImageWriter    = loader.create('com.google.zxing.client.j2se.MatrixToImageWriter')>
   7: <cfset QRcode     = QRCodeWriter.encode( 'http://cflove.org', BarcodeFormat.QR_CODE, 100, 100 )>
   8: <cfset image     = ImageNew( MatrixToImageWriter.toBufferedImage( QRcode ) )>
   9: <cfimage action="writeToBrowser" source="#image#" format="png">
Show/Hide Line Numbers . Full Screen . Plain

Download everything bellow

Download (qr.zip)
Name  
(required)
Email  
(required - never shown publicly)
Web Site  
Notify me of new comments via email.
Notify me of replies via email.
1 Comment :
pim_man
on Friday 06 January 2012 04:14 PM
Thank you :P