Jan
28
by Mike Fleming at 7:21 am (5 Comments) ColdFusion
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();
Mario
May 6, 20094:49 pm
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
Mike Fleming
May 7, 20097:39 am
Mario,
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
Lizam
July 22, 20109:32 am
Hi 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
Lizam
July 22, 20109:41 am
Hi Mike,
Just to add that when access through WAN, if pdf, I get a box with a sign ‘X’ inside.
Thanks,
Lizam
Mike Fleming
July 22, 201011:02 am
This 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.