Answered by:
Create a Generic/Text Printer Driver in C#

Question
-
How can we create a generic/Text Printer Driver in C#?
A code sample woul be much appreciated.
Thank you.
Wednesday, June 27, 2007 8:25 PM
Answers
-
You can't create printer drivers in a .NET language. You can however output raw print commands directly to the printer, bypassing the driver. Check this KB article for the P/Invoke required.Thursday, June 28, 2007 1:46 PM
All replies
-
You can't create printer drivers in a .NET language. You can however output raw print commands directly to the printer, bypassing the driver. Check this KB article for the P/Invoke required.Thursday, June 28, 2007 1:46 PM
-
There is something else that I want to do.
Actually I want to be capable to send a PrintDocument to a Serial Print.
For doing that I send PrintDocument to a File ( using the Generic/Text driver ) and then the file is sent to a serial printer.
Friday, June 29, 2007 2:10 PM -
Why send it to a file first? Just configure the printer to send output to a serial port directly. If the file is a requirement, you could print it by using Process.Start("print /d:COM1 path"). Or do it yourself with the .NET 2.0 SerialPort class.Friday, June 29, 2007 2:32 PM
-
I am not clear enough, I suppose.
The output is a PrintDocument.
The Printer is an Epson POS COM Printer , for which I didn't find any drivers. (XP or newer). That is the main problem in fact.
Good. Now the PrintDocument I have ( which allows me a nice preview if necessary), cannot be sent directly to the serial printer.
Therefore I had to use that Generic/Text driver to send the PrintDocument to a text file, first. And only afterwards to use SerialPort class for printing.
If, on the other hand, I set the port for the printer driver directly to COM , I have 2 issues.
1. The printing stops after it reaches the buffer size. I wasn't capable to manage that. Which I could controle programmatically using CtsHolding property with my SerialPort object
2. My application uses a third party EXE that also uses the serial port and it finds it inaccesible because of the Printer Driver.
Friday, June 29, 2007 3:05 PM -
You cannot use PrintDocument if you don't have a driver. You'll have to generate the printer escape codes yourself. You cannot open a serial port that is in use by another process. That would be a show-stopper problem I'd say.Friday, June 29, 2007 4:08 PM
-
Exactly. That's why I create/use a generic/text printer driver.
You cannot open a serial port that is in use by another process. - Right again, that's why I use that text file solution.
Thanks for confirming me what I was thinking.
Friday, June 29, 2007 4:14 PM