Question

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.

Was it helpful?

Solution

The iText library supports pretty much every kind of barcode imaginable. You can generate pdfs and either save them or print them internally.

OTHER TIPS

I suggest using the barcode4j library instead of barbecue for 2 reasons:

  1. 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.

  2. 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

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.

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.

Have you tried printing the image that you got from "barbecue" ?

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.

  1. Sending an initial newline guarantees that any previous borked command is submitted.
  2. [N] Clear the image buffer. This is an important step and generally should be the first command in any EPL document; who knows what state the previous job left the printer in.
  3. [q] Set the label width to 609 dots (3 inch label x 203 dpi = 609 dots wide).
  4. [Q] Set the label height to 203 dots (1 inch label) with a 26 dot gap between the labels. (The printer will probably auto- sense, but this doesn't hurt.)
  5. [B] Draw a UPC-A barcode with value "777777" at x = 26 dots (1/8 in), y = 26 dots (1/8 in) with a narrow bar width of 2 dots and make it 152 dots (3/4 in) high. (The origin of the label coordinate system is the top left corner of the label.)
  6. [A] Draw the text "JESUSLOVESYOU" at x = 253 dots (3/4 in), y = 26 dots (1/8 in) in printer font "3", normal horizontal and vertical scaling, and no fancy white-on-black effect.

All tha A starting lines are similar. 10. [P] Print one copy of one label.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top