如何从 Ruby on Rails 应用程序打印(条形码)标签?
我在 RoR 中开发的第一个应用程序是针对我们库存中使用的一些 Kiosk 触摸屏 PC。当库存工人拿起一些材料时,他在表格中输入数量。
现在我想在我们的 Zebra 打印机上打印一个标签,其中包含:客户名称、材料描述、数量和条形码。
我如何从 Ruby on Rails 应用程序执行此操作?
从控制器直接发送 ZPL(Zebra 打印机语言)所需的控制字符? (不是很舒服)
用 HTML 创建一个视图,将其发送到客户端,客户端必须打印它。 (不太舒服,而且容易出错,因为库存人员必须执行额外的步骤,可能会选择错误的打印机,或者可能根本不打印标签)
从控制器创建 pdf 文档并将其发送到打印机从服务器(哦,不,打印机不理解pdf,所以我必须控制pdf阅读器来进行打印?这不会很快,因为它将标签作为图形图像发送到打印机
创建一个 gem 来隐藏打印所需的所有逻辑?(是否有任何 gem 已经这样做了?)
我将不胜感激,
谢谢克劳斯
。
My first application I have developed in RoR is for some Kiosk Touchscreen PCs used in our stock. When the stock worker picked up some material he enters the quantity in a Form.
Now I want to print a label containing: customer name, material description, quantity, and a barcode on our Zebra printer.
How would I do that from a Ruby on Rails Application ?
Sending directly the control chars needed for ZPL (Zebra Printer Language) from the controller ? ( not very comfortable )
Create a view in HTML send it to the client, and the client has to print it. ( not very confortable and error prone, as the stock worker has to do additional steps, may choose the wrong printer or maybe don't print the label at all )
Create a pdf document from the controller and send it to the printer from the server ( oh, no the printer does not understand pdf, so I have to control a pdf reader to do the printing ?? That wouldn't be very fast as it will send the label as a graphic image to the printer
Create a gem which will hide all the logic needed for printing ? ( Are there any gems which already do this ? )
I would appreciate every comment.
Thanks
Klaus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会将原始 ZPL 发送到打印机。您可以使用 Bartender 之类的工具(我建议从该链接安装 Bartender Only。您基本上可以在此工具中设计标签后,您可以下载适合您的斑马打印机的调酒师打印机驱动程序,并使用这些驱动程序设置虚拟打印机,并将您设计的标签打印到文件中。由此,您基本上可以将所有动态数据替换到您在上一步中打印的 zpl 文件中,并通过串行、tcp/ip 或 USB 将其直接发送到打印机。
I would send the raw ZPL to the printer. You can use a tool like Bartender (I would suggest installing Bartender Only from that link. You can basically design your label in this tool. After you've designed your label you would download the bartender printer drivers for your zebra printer and set up a dummy printer with these drivers and print this label you designed to a file. This will give you the raw zpl. From this you can basically substitute all the dynamic data into the zpl file you printed in the previous step and send this directly to the printer via serial, tcp/ip or usb.
编辑:当我继续挖掘这个问题时,我找到了一个更好的解决方案。为了重点关注我最终使用的 Java applet 解决方案,本文进行了相当大的编辑。
基本上,您将生成原始 ZPL 文本形式的标签。然后,您需要将该纯文本发送到打印机,打印机将生成标签。
如果您的服务器可以访问打印机的 IP 地址,您可以直接从服务器进程将 ZPL 复制到打印机。如果它是远程 Web 应用程序,您需要让客户端为您发送 ZPL。浏览器沙箱使得这很难实现——驱动程序想要帮忙阻止。有几种选择;最常见的是使用小型 Java 或 Flash 小程序进行实际复制。如果您可以获得用户用于打印到纯文本打印机的特定 Web 浏览器,而无需添加任何内容,则可以使用本地打印,但通常最可靠的方法是使用帮助程序 Java 小程序。
我为此使用的 Java 小程序是 jZebra: http://code.google.com/p/jzebra/
这是一个非常干净的&简单的方法,查看下载包中的示例 HTML 和打印标签的几行代码。我刚刚编辑了示例,并计划将其用作我的生产代码弹出窗口..真的就是这么简单。
使用此方法的两个注意事项:
Edit: I found a much better solution as I continued to dig on this. This is pretty significantly edited down to focus on the Java applet solution I ended up using.
Basically, you will generate the label as raw ZPL text. You then need to get that plain text to the printer, which will generate the label.
If your server can access the printer's IP address, you can copy the ZPL to the printer directly from the server process. If it's a remote web app, you need to get the client to send the ZPL for you. Browser sandboxing makes this hard to pull off - drivers want to helpfully get in the way. There are a few options; the most common is to use a small Java or Flash applet to do the actual copying. If you can get the specific web browser your users are using to print to a plain text printer without adding anything, you could use local printing, but generally the most robust approach is to use a helper Java applet.
The Java applet I use for this is jZebra: http://code.google.com/p/jzebra/
It's a very clean & straightforward approach, look at the sample HTML in the download package and a few lines of code print the label. I just edited down the sample and am planning to use it as my production code popup.. it's really that straightforward.
Two caveats with this approach:
更简单的解决方案,我相信也更好,通常大多数浏览器和机器都安装了 PDF 查看器。因此,只需将标签创建为 PDF 文档并将其发送到浏览器即可。
我们已经按照以下方式使用 Zebra 打印机实现了标签打印。
通常标签也包含条形码。
因此,总体解决方案是,
More simple solution, and I believe better as well, Usually most of browser and machines has PDF viewer installed. So just create labels as PDF documents and sent it to browser.
We have implemented label printing using Zebra printer in ROR following way.
Usually labels contains barcodes as well.
So overall solution would be,
听起来像是 ruby C 扩展的工作。也许还包含诸如 gnu 条形码之类的东西 http://www.gnu.org/software/barcode/< /a> 斑马打印机的库和其他一些开放标准(如果存在)?我曾经做过一个 Rails 应用程序,它可以制作优惠券并大量使用 GNU 条形码,但我使用了简单的 shell 命令来连接它。
Sounds like a job for a ruby C extension. Perhaps one that also wraps something like gnu barcode http://www.gnu.org/software/barcode/ library and some other open standard for the zebra printer, if one exists? I once did a rails app that made coupons and made heavy use of gnu barcode, but I did simple shell command to interface to it.