Print barcodes from web page to Zebra printer

user1447134 picture user1447134 · Jun 10, 2012 · Viewed 55.8k times · Source

We're trying to print barcodes from a web page to our Zebra printer.

I'm wondering if there's a way to print them using the printer's own font perhaps using web fonts or if I knew the font name used?

I have been trying to use php barcode generators, that basically generates images containing the barcode. I have in fact been trying this approach for a few days already, without success.

The problem is when I print them it's not readable by the scanners. I have tried to change the image resolution to match that of the printer (203dpi), also tried playing with the image size and formats, but the barcodes after printed still can't be scanned.

So does anybody have experience with this?

Printer: Zebra TLP 2844

Barcodes required per page:

  • 01 Code39 horizontal (scanable only if printed at very specific size and browser)
  • 01 Code128 vertical (still can't get it to work, print is always very blurry and won't get scanned)

===========

I've made a little bit of progress, I found out this printer supports EPL2 language, so I'm trying to use it to print out the barcodes.

First I needed to enable pass through mode, I did that on Printer Options > Advanced Setup > Miscellaneous.

Now I'm able to print barcodes impeccably using the printer's built-in font :D using this command:

ZPL: B10,10,0,1,2,2,60,N,"TEXT-GOES-HERE" :ZPL

But I can only print it from Notepad, I'm still unable to print this from a browser... It's probably a problem with LF being replaced with CR+LF...

How to overcome this problem??

===========

The label I'm trying to print actually has a bit of text before the barcode, with some html tables formatting it nicely. So I need to print this first, and in the middle I need to stick in a nice label and then add some more text.

So I can't use pure EPL2 to print the whole thing, I'm wondering if I can use some of both html + EPL2 + html to achieve my goal or is that not allowed?? =/

Answer

dmarietta picture dmarietta · Jun 12, 2012

You are running into a few obstacles:

1) When you print through the OS installed printer driver, the printer driver is trying to take the data that is sent to it and (re)rasterize or scale it for the output device (the Zebra printer). Since the printer is a relatively low resolution at 203dpi, then it does not take too much for the scaling the print driver is having to do for it to loose some integrity in the quality of the barcode. This is why barcodes generated using the direct ZPL commands are much more reliable.

2) Due to the security that web browsers purposefully provide by not allowing access to the client computer, you cannot directly communicate with the client connected printer. This sandboxing is what helps to protect users from malware so that nefarious websites cannot do things like write files to the client machine or send output directly to devices such as printers. So you are not able to directly send the ZPL commands through the browser to the client connected printer.

However, there is a way to do what you describe. The steps necessary are typically only going to be useful if you have some degree of control over the client computer accessing the site that is trying to print to the Zebra printers. For example this is only going to be used by machines on your company network, or by clients who are willing to install a small application that you need to write. To do this, you will need to look at the following steps:

A) You need to make up your own custom MIME type. This is basically just any name you want to use that is not going to collide with any registered MIME types.

B) Next you will define a filename extension that will map to your custom MIME type. To do this, you typically will need to configure your web server (steps for this depend on what web server you are using) to allow the new MIME type you want to define and what file extension is used for these types of files.

C) Then on your web application, when you want to output the ZPL data, you write it to a file using a filename extension that is mapped to your new MIME type. Then once the file is generated, you can either provide an HTML link to it, or redirect the client browser to the file. You can test if your file is working correctly at this point by manually copying the file you created directly to the raw printer port.

D) Next you need to write a small application which can be installed on the client. When the application is installed, you need to have it register itself as a valid consuming application for your custom MIME type. If a browser detects that there is an installed application for a file of the specified MIME type, it simply writes the file to a temporary directory on the client machine and then attempts to launch the application of the same registered MIME type with the temporary file as a parameter to the application. Thus your application now just reads the file that the browser passed to it and then it attempts to dump it directly to the printer.

This is an overview of what you need to do in order to accomplish what you are describing. Some of the specific steps will depend on what type of web server you are using and what OS your clients machines are. But this is the high level overview that will let you accomplish what you are attempting.