I was reading a thread in the Brazilian ColdFusion group where Vinícius Guimarães posted an interesting solution for printing barcode from a CF application.
First download the Barbecue Java library from SourceForge. Here is the link for the entire Barbecue Project.
Once you download the library, expand the zip file and copy the barbecue-1.5-beta1.jar to the folder: ColdFusion8\runtime\lib.
Ok, you are now ready to use barcode from ColdFusion, just need to create the component barcode.cfc below:{code type=xhtml}<cfcomponent>
<cffunction name=”getCode128″ returntype=”any” access=”remote” output=”true”>
<cfargument name=”data” type=”string” required=”true” />
<cfsetting showdebugoutput=”false”>
<cfscript>
Barcode = createObject(“java”, “net.sourceforge.barbecue.linear.code39.Code39Barcode”).init(data, false, true);
BarcodeImageHandler = createObject(“java”, “net.sourceforge.barbecue.BarcodeImageHandler”);
Barcode.setDrawingText(false);
Barcode.setBarHeight(50);
Barcode.setBarWidth(2);
context = getPageContext();
context.setFlushOutput(false);
response = context.getResponse().getResponse();
response.setContentType(“image/jpeg”);
BarcodeImageHandler.writeJPEG(Barcode, response.getOutputStream());
response.flush();
response.close();
</cfscript>
<!—Return the information as streaming bytes of type image/jpeg—>
<cfreturn>
</cffunction>
</cfcomponent>{/code}
Then, to call this component, here is a small test template:{code type=xhtml}<cfif structKeyExists(form, “barVar”)>
<cfoutput>
<img src=”barcode.cfc?method=getCode128&data=#form.barVar#” />
</cfoutput>
</cfif>
<form action=”barcodeTest.cfm” method=”post”>
Enter value: <input name=”barVar” type=”Text” size=”15″ />
<input type=”Submit” value=”GO” />
</form>{/code}
#barVar# is the number you want to print as a barcode.
Remember that each barcode reader reads a type of barcode, in this case we are using Code128.
Great article. To print barcodes you can also use a barcode font. The Cold Fusion demo is really cool though.
You can also achieve this (creating a barcode) using a simple font installable on all OS’s (Z: 3of9 BarCode).
Thank you. And like WordPress? Sometimes it is necessary to publish the code in the post.
How you install that on Coldfusion 8 running JRUN 4?
Putting the JAR in the C:\JRUN4\lib folder hung everthing up!!!
How might one go about reading barcodes from image files
Geoffrey, to read the barcodes you need to print them and scan them with a barcode scanner. You can get them as cheap as $60 and plug them into to your USB port, prints directly to screen.
Hi, thank you for your work!.
When you use barbecue on Linux (Centos 5, Ubuntu) is not possible to drawing text below the barcode.
I set Barcode.setDrawingText(true).
Have You any idea?
Thank you
Angelo
If you are looking to get a code128 barcode using this example, make sure to change the line:
Barcode = createObject(“java”, “net.sourceforge.barbecue.linear.code39.Code39Barcode”).init(data, false, true);
to
Barcode = createObject(“java”, “net.sourceforge.barbecue.linear.code128.Code128Barcode”).init(data);
Hi
Ive tried this but all im getting is a blank screen after i click on submit
I’ve put “barbecue-1.5-beta1.jar” in the correct location
is there anything else in that zipfile that needs to go anywhere?
any ideas?
Thanks
have you restarted your cf?
I have item codes on a csv file which i upload to a browser using coldfusion, using this item code im trying to generate a bar-code for it using the above code
Ricardo:
Seems pretty straightforward – put the .jar file in my Lib directory and the Barcode.cfc in the same directory as the demo file, but all I get is a failed graphic box with the red X in it, so it does not look as if the CFC is doing anything.
Any thoughts?
Thanks
Same problem as Ted Daniels…
Thanks for help
Olivier
It works now, after a stop/start of the CF server…
Thanks!
great one. Helped me alot
it worked with me, thanks a lot!
if i can only get you, i’ll kiss you!
I was able to print the carcode, but if I want to place anuthing else in the output page, I cannot. Any idea of what need to be done, if the barcode is only one of many elements on the page ?
The barcode part worked fine but I am getting the following error message:
Any help is appreciated..
The flush method was not found. Either there are no methods with the specified method name and argument types or the flush method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity. The error occurred on line 16.