views:

3311

answers:

8

I'm looking to create a virtual printer that passes data to my .NET application. I want to then create an installer that installs both the printer and the .NET application. It would we really nice to be able to write it all in C#, but I have a feeling that this will require a printer driver to be written is unmanaged code. Does anyone know of a fairly clean tutorial or example of how to do this?

+7  A: 

I think you will have to do a lot of WinAPI wrapping. Start researching on Windows Driver Development Kit to find the things you have to do.

I also found this commercial Printer Driver Resource Toolkit for .NET...

CMS
+2  A: 

You can't. The Windows driver model is native.

Aidan Ryan
He can't what exactly? Write a "virtual printer? Of course he can. Create an installer that installs a virtual printer and a .NET application? Of course he can. Write it all in C#? Depends on your definition of "all" and "in C#".
bzlm
A: 

Why not consider using an alternative approach. Like using an intermediate ready made printing program, such as those freely available Print-to-PDF application. Then all you need is to decode PDF using some 3rd party library (which has free and opensource variance too) instead of cracking your head to reinvent the wheel. There are other Print-to-XXX application which you could also consider depending on the format you see fit.

faulty
+1  A: 

I don't thing interpreting PDF approach is any good either. I don't know why you want to do what you want to do. Maybe you're trying to write a PDF printer of your own.

I think you should really give the Windows Driver Development thing a look. If you want to develop a printer driver, I think you'll have to do it in C++.

Good Luck.

Cyril Gupta
+2  A: 

You could simply have your app expose itself like an LPD type printer or monitor port 9100. You could then install any print driver you like, and point it a your app.

Douglas Anderson
Nice idea. But what about parsing the "LPD data", or whatever comes through the port?
bzlm
Typically 515, it like most things, is user definable but more often then not it's that. LPD is nice as there is a small header that contains information like destination queue etc. followed by the actual data. Just capture some data and you will see, it's pretty simple.
Douglas Anderson
+2  A: 

Was looking for an answer for similar question, and found this link through Wikipedia - http://www.colorpilot.com/emfprinterpilot.html (allows to create Virtual Printers in different languages)

dolzenko
A: 

If I remember correctly Microsoft does not support .NET within printer driver development. I have yet to come across a pure .NET printer driver. You will be a very brave man to do so! The website "Printer Driver Resource Toolkit" does not say that the driver has been written in .NET

PDK
A: 

David Osborn did you find an answer to your question? If so I like to know because I'm facing the same problem.

Zerone
You might want to add this as a comment instead of an answer...because it isn't an answer.
NickAldwin
I tried to but the Add Comment was not available for the question or any of the answers, that is why I had to add it as an answer.
Zerone