从Java应用程序向Zebra打印机发送条形码 [英] Sending a Barcode to a Zebra Printer from a Java Application

查看:228
本文介绍了从Java应用程序向Zebra打印机发送条形码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个java应用程序,它从数据库中检索userId,将其转换为条形码,然后将其发送到打印机。我打算使用Zebra打印机,我想知道是否有人有从Java应用程序打印到Zebra打印机的经验;如果是这样,你能分享一些代码吗?

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?

提前致谢,
Tumaini

Thanks in advance, Tumaini

推荐答案

有两种方法可以使用Zebra打印机。第一种是在普通打印机上打印。 Java打印基础知识在官方教程中有详细说明。页面的末尾将被打印机视为贴纸的末尾。这种方法的缺点是所有的绘画都必须用手完成。即你不能使用内部打印机的条形码能力。

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.

第二种是将ZPL命令直接写入打印机。这样的事情:

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);

缺点是你需要学习ZPL - Zebra编程语言。虽然它很简单,但像图像和自定义字体这样的东西可能会让你头疼。 Zebra网站免费提供编程手册:第1部分第2部分

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.

这篇关于从Java应用程序向Zebra打印机发送条形码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆