如何从 Ruby on Rails 应用程序打印(条形码)标签?

发布于 2024-10-29 22:26:52 字数 550 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

欢烬 2024-11-05 22:26:52

我会将原始 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.

思念绕指尖 2024-11-05 22:26:52

编辑:当我继续挖掘这个问题时,我找到了一个更好的解决方案。为了重点关注我最终使用的 Java applet 解决方案,本文进行了相当大的编辑。

基本上,您将生成原始 ZPL 文本形式的标签。然后,您需要将该纯文本发送到打印机,打印机将生成标签。

如果您的服务器可以访问打印机的 IP 地址,您可以直接从服务器进程将 ZPL 复制到打印机。如果它是远程 Web 应用程序,您需要让客户端为您发送 ZPL。浏览器沙箱使得这很难实现——驱动程序想要帮忙阻止。有几种选择;最常见的是使用小型 Java 或 Flash 小程序进行实际复制。如果您可以获得用户用于打印到纯文本打印机的特定 Web 浏览器,而无需添加任何内容,则可以使用本地打印,但通常最可靠的方法是使用帮助程序 Java 小程序。

我为此使用的 Java 小程序是 jZebra: http://code.google.com/p/jzebra/

这是一个非常干净的&简单的方法,查看下载包中的示例 HTML 和打印标签的几行代码。我刚刚编辑了示例,并计划将其用作我的生产代码弹出窗口..真的就是这么简单。

使用此方法的两个注意事项:

  • 您的用户必须安装 JRE
  • jZebra 按打印机名称查找 Zebra 打印机。对于您需要执行的操作,有非常具体的指南(其中有针对 Mac、Windows 和 Linux 设置的详细说明),但它有详细的文档记录,您只需让用户遵循说明即可。一旦设置正确,它就可以很好地工作。

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:

  • Your users must have the JRE installed
  • jZebra finds the Zebra printer by printer name. There are very specific guides (they have detailed instructions for Mac, Windows, and Linux setup) for what you need to do - but it's well documented and you just have to have your users follow the instructions. Once it's set up correctly it works great.
掐死时间 2024-11-05 22:26:52

更简单的解决方案,我相信也更好,通常大多数浏览器和机器都安装了 PDF 查看器。因此,只需将标签创建为 PDF 文档并将其发送到浏览器即可。

我们已经按照以下方式使用 Zebra 打印机实现了标签打印。

  1. 在 html 中创建精确格式的标签页面。
  2. 使用 wickedPDF 将 html 转换为 pdf。

通常标签也包含条形码。

因此,总体解决方案是,

  1. 使用 barbie gem 创建条形码。
  2. 使用条形码和需要贴在标签上的实际数据创建 html。
  3. 将 html 视图转换为 PDF。

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.

  1. Create exact format label pages in html.
  2. Convert the html to pdf using wickedPDF.

Usually labels contains barcodes as well.

So overall solution would be,

  1. Create barcodes using barbie gem.
  2. Create html using barcodes and your actuall data that needs to go on label.
  3. Convert html view to PDF.
放我走吧 2024-11-05 22:26:52

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文