Wednesday, February 24, 2010

Print Zebra barcode label thru' ASP .NET

Recently, one of the projects I am maintaining required me to enhance the existing feature, which is printing the Zebra barcode label through ASP .NET. The old staff who developed it left the company long time ago, and there's no other colleagues know how it was developed and worked.

Printing it as WinForm application is not uncommon with the SerialPort Class, as there's a lot of resources out there, but not so true for ASP .NET.

So I needed to google around and posted question to the forums. With some lucks and googling skills, i managed to let it works and add enhancement on that. But i found not full steps on web, so just to post this to help someone who might need it in the future.

1.a) Set the "Generic/Text Only" as default printer driver. Yes, you see it correctly, it's not zebra printer driver that match your zebra printer, since it's printed through web.


1.b.i) If you do not have it, you can go to any existing printer property page (right-click on any other printer driver) and add this driver.


1.b.ii) Browse to driver list start with "G", then you will find it. Finish this installation process.


2) Once you have the driver, setup the ASP designer with Zebra programming language (ZPL) like this (The buttons are for user to trigger the ZPL to send).

3) By calling the undocumented print() function (not window.print(), and I think it works on IE only) in javascript, you can print the zebra bar-code label through ASP.NET.

4) Keep the web form as clean code as possible, you will send it as ZPL and ZPL only to printer.

5) Print it! You should get it ;)

9 comments:

Craig said...

Very nice solution! I have a question, however. Will this work in a scenario where the client pc is not directly connected to the label printer (i.e. the label printer is a network printer to the client of the app). Seems that specifying the Generic/Text print driver on the client would prohibit choosing the desired network resource? I'm hoping i'm wrong :)

gary said...

network resource? I do no think it works, unless that network printer is specified the Generic/Text print driver. :D

Fernando said...

Thank you very much for your post.
I'm trying to print a barcode label from a web page and i don't understand where you see the result of the print() instruction.

I have not installed any driver of Zebra. I only have my EPSON printer :)

I have selected de Generic/Text Only driver but when i press "Print" button and select the printer nothing happens.

Thanks for your help.
Regards.

gary said...

EPSON printer? Hmmm..., no idea.
this print() command is undocumented, I also could not find it thru' google, and it's in the part of the existing code that left from my previous colleague.

olen said...

I'm trying to print to a LP 2844. If I change the driver to generic/text only, the printer does not respond to the print request. If I change the driver back to zebra, then it does not interpret the EPL. I have to use EPL on this printer and not ZPL.

Any help is appreciated.

Rahul Mehta said...

what is that zebra programming code and where u get it from

its urgent?

Rahul Mehta said...

what is that zebra programming code.

can u put more light on that

its little urgent

Craig Fordham Site Admin said...

Great idea of printing the Zebra barcode
Plastic Card Printer

Swapnil said...

Can you send the code for the same?...If possible send it on

swapnil.k.fegade@gmail.com