Reputation: 243
Can someone point in the right direction for printing barcode labels using Java? I can use the barbecue library (http://barbecue.sourceforge.net/) to generate them bar codes as images, but I need a way to put the image (and human readable caption) into an Avery document template for printing.
Upvotes: 2
Views: 14736
Reputation: 5454
You should try JZebra this is an applet and a good start point for you, take a look at the java source code.
http://code.google.com/p/jzebra/
For zebra you this simple guide will help you. On this Zebra commands
N
q609
Q203,26
B26,26,0,UA0,2,2,152,B,"777777"
A253,56,0,3,1,1,N,"JHON3:16"
A253,26,0,3,1,1,N,"JESUSLOVESYOU"
A253,86,0,3,1,1,N,"TEST TEST TEST"
A253,116,0,3,1,1,N,"ANOTHER TEST"
A253,146,0,3,1,1,N,"SOME LETTERS"
P1,1
on JZebra
var applet = document.jzebra;
if (applet != null) {
applet.append("N\n");
applet.append("q609\n");
applet.append("Q203,26\n");
applet.append("B26,26,0,UA0,2,2,152,B,\"777777\"\n");
applet.append("A253,56,0,3,1,1,N,\"JHON3:16\"\n");
applet.append("A253,26,0,3,1,1,N,\"JESUSLOVESYOU\"\n");
applet.append("A253,86,0,3,1,1,N,\"TEST TEST TEST\"\n");
applet.append("A253,116,0,3,1,1,N,\"ANOTHER TEST\"\n");
applet.append("A253,146,0,3,1,1,N,\"SOME LETTERS\"\n");
applet.append("P1,1\n");}
Having clear this:
EPL is one command per line. A command starts out with a command identifier, typically a letter, followed by a comma-separated list of parameters specific to that command. You can look up each of these commands in the EPL2 programming documentation. Here’s an English-language version of the commands in the above example.
All tha A starting lines are similar. 10. [P] Print one copy of one label.
Upvotes: 0
Reputation: 6800
I suggest using the barcode4j library instead of barbecue for 2 reasons:
Barbecue barcode objects are unnecessarily coupled to Java UI components (e.g. Barcode class extends JComponent). This creates unnecessary dependencies if the Java UI is not being used, e.g. for batch or command line based applications. They should have used aggregation rather than inheritance if they wanted to use their barcode classes with the Java UI.
Barcode4J looks like it is currently supported - version 2.0 released and copyright date is 2012
Then you have the problem of translating the barcode into a format that your printer understands. For this I suggest openlabelprint.org (which I wrote!) - it's another open source project that uses barcode4j and provides:
facilities to define a label layout using SVG (Scalable Vector Graphics - an open w3c standard) and
rasterization to a bitmap of the SVG from barcode4j (and the surrounding label layout in SVG) (openlabelprint applies the excellent Apache SVG Batik Java libraries for rasterization as well as for other SVG tasks)
printing of the bitmap on Zebra printers using their ZPL low level language. openlabelprint has a built in utility to convert png bitmaps to ZPL and send this to the Zebra printer via the standard Java printer system. Also openlabelprint provides APIs to extend it for other printer languages though ZPL is supported by some non-Zebra brands
Upvotes: 3
Reputation: 6072
The iText library supports pretty much every kind of barcode imaginable. You can generate pdfs and either save them or print them internally.
Upvotes: 3
Reputation: 3720
I'm printing bar codes using java but I'm using a printer which have a pre-programmed function for printing bar codes. So I'm only telling the printer what codes to print and it does the rest. If you willing to pay for a printer it might saves you some time.
This may or may not be useful to you, but I thought i'd mention it.
Upvotes: 2
Reputation: 9872
I think you will have to measure your Avery label page with a ruler and then in your Java code, you will have to create a full Letter/A4/whatever page to print and offset your barcode image on that page to the appropriate location based on your measurements with the ruler.
Upvotes: 1