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.
myBarcodeobj = CreateObject("Java", "net.sourceforge.barbecue.Barcode");
myBarcodeFactory = CreateObject("Java", "net.sourceforge.barbecue.BarcodeFactory");
myBarcodeImageHandler = CreateObject("Java", "net.sourceforge.barbecue.BarcodeImageHandler");
myBarcodeobj=myBarcodeFactory.createCode128C(variables.barcodeNumber);
myBarcodeobj.setResolution(100);
myBarcodeobj.setBarWidth(1);
myBarcodeobj.setBarHeight(30);
myBarcodeobj.setDrawingText(false);
Image = myBarcodeImageHandler.getImage(myBarcodeobj);
ImageIO = CreateObject("Java", "javax.imageio.ImageIO");
OutputStream = CreateObject("Java", "java.io.FileOutputStream");
OutputStream.init(variables.imagePath);
ImageIO.write(Image, "jpg", OutputStream);
Image.flush();
OutputStream.close();
Hi Mike,
This looks really useful. Would it be possible to get a sample of the actual code used. I have been looking at using barbecue but I have been having issues and I am relatively new to using Java with CF.
Thanks
Mario
Posted by Mario | May 6, 2009, 8:49 PMHi Mike,
This looks really useful. Would it be possible to get a sample of the actual code used. I have been looking at using barbecue but I have been having issues and I am relatively new to using Java with CF.
Thanks
Mario
Posted by Mario | May 6, 2009, 4:49 PMMario,
The code contained in the post is the actual code I am using. You just need to replace the variables for the image path (where it writes the created image creating the bar code) and the actual bar code number itself. As far as code that is all you need.
You do need to download the library itself (if you search on Google for it you will see the SourceForge project for it). You need to place the files somewhere in your ColdFusion directory that is already referenced in the class path variables or you can place them in a new folder and update the class path to look there.
Mike
Posted by Mike Fleming | May 7, 2009, 7:39 AMHi Mike,
I have a strange scenario where the program works fine if access from LAN but not through WAN (only if pdf, html still works though). Any idea what could be the cause?
The client is running latest JRE since the requirement is 1.4 or higher. Any other specific requirements at the client machine?
Really appreciate your help.
Thanks,
Lizam
Posted by Lizam | July 22, 2010, 1:32 PMHi Mike,
I have a strange scenario where the program works fine if access from LAN but not through WAN (only if pdf, html still works though). Any idea what could be the cause?
The client is running latest JRE since the requirement is 1.4 or higher. Any other specific requirements at the client machine?
Really appreciate your help.
Thanks,
Lizam
Posted by Lizam | July 22, 2010, 9:32 AMHi Mike,
Just to add that when access through WAN, if pdf, I get a box with a sign ‘X’ inside.
Thanks,
Lizam
Posted by Lizam | July 22, 2010, 1:41 PMThis sounds like a permissions issue. It writes out a file to disk. You may want to check to make sure whatever folder it’s generating the barcode image to is accessible from the WAN.
Posted by Mike Fleming | July 22, 2010, 3:02 PMHi Mike,
Just to add that when access through WAN, if pdf, I get a box with a sign ‘X’ inside.
Thanks,
Lizam
Posted by Lizam | July 22, 2010, 9:41 AMThis sounds like a permissions issue. It writes out a file to disk. You may want to check to make sure whatever folder it’s generating the barcode image to is accessible from the WAN.
Posted by Mike Fleming | July 22, 2010, 11:02 AMhi mike
i want tomake the bakeground of the barcode transparent. how can we do that ?
Posted by talha | July 17, 2011, 7:15 AM