Using the Barbecue Java Library in ColdFusion to Create Barcodes

A few years ago I was tasked with creating some dynamic PDF files that contained  a couple of barcodes in them.  I started looking around for components or libraries that I could use through ColdFusion to feed the images into CFDOCUMENT.  I stumbled across an open source Java library named Barbecue (clever name!).  Since ColdFusion can call Java libraries with no problem, I gave it a shot. 

In short, this library rocks!  I have been using this library for three years now on a very high traffic site.  On certain days it has created hundreds of thousands of barcode images and has never choked.  If you are needing to generate barcodes I would highly recommend this library.  Below I have provided a little code snippet on how you call this library via ColdFusion.

<code lang="cfm[lines]"><cfscript><br></br>
myBarcodeobj = CreateObject("Java", "net.sourceforge.barbecue.Barcode");<br></br> myBarcodeFactory = CreateObject("Java", "net.sourceforge.barbecue.BarcodeFactory");<br></br> myBarcodeImageHandler = CreateObject("Java", "net.sourceforge.barbecue.BarcodeImageHandler");<br></br> myBarcodeobj=myBarcodeFactory.createCode128C(variables.barcodeNumber);<br></br> myBarcodeobj.setResolution(100);<br></br> myBarcodeobj.setBarWidth(1);<br></br> myBarcodeobj.setBarHeight(30);<br></br> myBarcodeobj.setDrawingText(false);<br></br> Image = myBarcodeImageHandler.getImage(myBarcodeobj);<br></br> ImageIO = CreateObject("Java", "javax.imageio.ImageIO");<br></br> OutputStream = CreateObject("Java", "");<br></br> OutputStream.init(variables.imagePath);<br></br> ImageIO.write(Image, "jpg", OutputStream);<br></br> Image.flush();<br></br> OutputStream.close();<br></br></cfscript>


comments powered by Disqus