Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print (barcode) labels from a Ruby on Rails Application?

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

like image 508
Klaus Avatar asked Apr 03 '11 14:04

Klaus


People also ask

Can you print out barcode?

If you're creating barcode labels using a retail POS, an online site, or another software system, you can download your barcodes, convert them to a document, and use a regular printer and label sheets to print out your barcode labels.


2 Answers

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.

like image 118
Cole W Avatar answered Sep 19 '22 11:09

Cole W


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.
like image 37
Thaeli Avatar answered Sep 19 '22 11:09

Thaeli