For the last two days, I have been trying to find a way to send raw commands through C# to a label printer shared from a remote location. Now, if I was printing ‘Lord of the Rings’ on an A4 on this printer, I wouldn’t really mention it here, would I? My printer is a DataMax E-Series label printer (with a parallel interface) which was shared from a desktop (i know we can use a ethernet print server, but trust me, it doesn’t matter) ; I had this printer added to active directory so that i can print to it directly from any server. By the way, I am trying to print barcode labels to this printer. I figured there is a right way to do this and a crappy way:
a. The right way – These label printers are usually industrial quality and come with a 200 page programming manual, Â Â Â whereby we can send “raw” commands to make the printer sing, dance, and do the tango. Although the .net framework doesn’t have low-level printing functionality, we can import the relevant functions from the Win32 API. MS is kind enough to provide exquisite details on how to do this (link).Â This works great – for local printers only; for some reason the OpenPrint function imported from winspool.drv doesn’t work with network printers in .net. Googling for this revealed several other frustrated users reporting the same. Some of these folks reported that they got the raw commands to work with network printers from VB6. However much I hate doing it, my last option would be to write a little VB component, probably create a .net wrapper and use it.
b. The crappy way – Printing directly using PrintDocument, as it does not give me access to the exquisite library of commands that i can use in raw mode. By the way, direct printing works like a charm, of course formatting anything to make it fit a label from code is a nightmare.Â Though I make it sound bad, formatting might not be that hard – set margins, etc in the PrinterSettings class, override the print start/end/etc methods of the PrintDocument and render graphics of everything I need to use.
I will be using the direct print option as of now and try my hand at manual formatting, but I sure wish MS fixed the bugs with the OpenPrint and got it to work with network printers.
There are several posts out there about this, I think taking there reference could have made this post or article really informative. I am not saying this information is not good. But I must say that the information provided here was unique, but to make it more near to complete, supporting with other previous information will have been really good. The points you have touched here are really important, so I will post some of the information here to make this really good for all the newbieâ€™s here. Thanks for this information. Really helpful!