java调用zebra,从Java应用程序向Zebra打印机发送条形码

本文介绍了如何从Java应用程序中与Zebra打印机交互,包括两种方法:一是通过Java打印基础将条形码视为普通文本打印,二是直接发送ZPL指令到打印机进行更复杂的操作。第二种方法需要熟悉Zebra编程语言(ZPL),虽然简单但处理图像和自定义字体可能会带来挑战。ZPL的编程手册可在Zebra官方网站上找到。
摘要由CSDN通过智能技术生成

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

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值