I am creating a java application that retrieves a userId from a database, transforms it into a barcode, then sends it to a printer. I am planning to use a Zebra printer and I was wondering if anyone has experience of printing to a Zebra printer from a Java application; if so, could you share some code making this possible?
Thanks in advance, Tumaini
Under the dashboard, tap Product Setup. Find your item by using the search bar or tapping its corresponding Category and Subcategory. Then tap OK, then choose Print Labels. Labels should print directly from the Zebra Printer.
There are two ways to work with Zebra printers. The first is to print as on regular printer. Java printing basics are well explained in official tutorial. End of page will treated by printer as end of sticker. The disadvantage of this approach is that all painting must be done by hands. I.e. you can't use internal printer's barcoding ability.
The second is to write ZPL commands directly to printer. Something like this:
PrintService pservice = ... // acquire print service of your printer
DocPrintJob job = pservice.createPrintJob();
String commands = "^XA\n\r^MNM\n\r^FO050,50\n\r^B8N,100,Y,N\n\r^FD1234567\n\r^FS\n\r^PQ3\n\r^XZ";
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(commands.getBytes(), flavor, null);
job.print(doc, null);
The disadvantage is that you need to learn ZPL - Zebra Programming Language. Although it is simple enough, but such things as images and custom fonts could make you headache. Programming manuals are freely available on Zebra site: Part 1 and Part 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With