Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am working on a project where I have to print to a barcode printer(Zebra GC420t) directly from the webpage. The issue I'm facing is, when I print it through my source code, the print succeeds. But, it fails when hosted to a web server. The code I'm using is:
C#
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();

void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
   System.Drawing.Font printFont = new System.Drawing.Font("IDAutomationHC39M", 9);
   SolidBrush br = new SolidBrush(Color.Black);
   ev.Graphics.DrawString("test", printFont, Brushes.Black, new RectangleF(5, 30, 180, 50));
}

What would be the issue. Is this a network related issue or should I change it to a client side code like javascript. Suggest me with some good solutions.

Thanks in advance,
Ranjith
Posted
Updated 18-Sep-13 1:26am
v2
Comments
[no name] 18-Sep-13 7:15am    
It is probably failing because your printer is not plugged into your web server.... right? Yes you would need to change this to client side code.
V.Lorz 18-Sep-13 9:11am    
And if you plug your printer in your server all labels will get printed there, possibly too many miles away from the client.

In some cases, in fact little bit more complicated cases like printing the label and at the same time encode one RFID tag attached to it using the Zebra's RFID reader/writer (not present in all Zebra printers), when you need direct access to specific hardware connected to the client's computer it becomes necessary to write one applet or one ActiveX component.

In your case it could be possible to generate (render) one image with the content to be printed and let the user redirect it to the Zebra printer.

1 solution

Your code will not work if you expect it to be printed at the client printer because your code runs at server side and will try to print to the printer available at that server.
To print to client printer use:

1. javascript code i.e. the classic window.print (https://www.google.com/#q=asp.net+window.print[^])

2. or try some reporting tool like free ReportViewer RDLC reports (http://www.gotreportviewer.com/[^])

3. or try sending raw Zebra commands to the printer:

http://start-coding.blogspot.com/2010/02/print-zebra-barcode-label-thru-asp-net.html[^]
http://forums.asp.net/t/1835622.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900