Klaus
Klaus

Reputation: 902

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 ?

I would appreciate every comment.

Thanks

Klaus

Upvotes: 6

Views: 8085

Answers (4)

Red Boy
Red Boy

Reputation: 5729

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.

Upvotes: 1

Thaeli
Thaeli

Reputation: 1108

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.

Upvotes: 2

Cole W
Cole W

Reputation: 15303

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.

Upvotes: 4

MetaSkills
MetaSkills

Reputation: 1854

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.

Upvotes: 0

Related Questions