1

I am new to windows development and I am trying to write a user-mode windows(XP, Vista & 7) virtual printer driver. My aim is to intercept the output being sent to the hardware printer by a third party app and add some extra data(text + graphics) to that output towards the end of the output. Then send the final payload to be printed by the hardware printer. Note that my data would not be added to every print out from the machine but just from a particular third party app.

I want to add my extra data to the print output before it gets converted to any Page Description Language(PDL). Can I do this? Would I be able to predictably add my extra data at the end of the output with proper formatting? If yes, then what kind of driver would I need to write and at what layer of the architecture ?

Is there a better way to do the same thing then writing a user-mode printer driver?

Finally, is there a sample code, online blog or book which can help me with this ?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
mabicha
  • 337
  • 2
  • 7
  • 16
  • possible duplicate of [How to create a virtual printer in Windows?](http://stackoverflow.com/questions/1019036/how-to-create-a-virtual-printer-in-windows) – Ken White Jun 08 '12 at 17:20
  • How do you intend to identify the printing app? – Carey Gregory Jun 14 '12 at 21:09
  • Since I am planning to write a printer driver, it will appear as one of the choices for the app to choose for printing. So when a print request comes to my printer driver, I will assume it is from that particular app itself. – mabicha Jun 15 '12 at 05:02
  • I don't think you need a driver. Just use the standard Postscript driver provided with the WDK, adding .PPD and .INF files to name it and specify characteristics, and then put your code in a port monitor. Port monitors are considerably easier to build and maintain than print drivers. – Carey Gregory Jun 15 '12 at 16:33
  • @CareyGregory : Thanks a lot Carey! Actually I am exploring the option of using port monitor for my purpose. Can you please add your comment as answer? Also, I am trying to install WDK sample port monitor(localmon) on windows 7 using [this link](http://msdn.microsoft.com/en-us/library/windows/hardware/ff551668(v=vs.85).aspx). But I keep getting this error: "An error occurred while copying file ddklocalmon.dll. Cannot copy file to destination folder." If this is a permissions issue then I am not sure, how to perform this operation as administrator. Can you please help ? – mabicha Jul 02 '12 at 17:31
  • Done. Installing the port monitor is unlikely to be a permissions issue if you're running as admin. If you're still having trouble installing it, post it as a new question and show the .inf file you're using. – Carey Gregory Jul 03 '12 at 02:23
  • @CareyGregory : Thanks again Carey! I changed permissions of system32 folder and now I am not getting "Cannot copy file to destination folder" error. But now I am getting following error: "An error occurred while installing port monitor 'DDK sample port monitor'. Please contact manufacturer for assistance." . As you requested I have posted the [new question here](http://stackoverflow.com/questions/11306787/error-while-installing-windows-sample-port-monitor-localmon) . – mabicha Jul 03 '12 at 08:06

2 Answers2

2

I think you'd be better off getting the application to write to a generic Postscript driver and post-processing the resulting Postscript rather than trying to make sense of the data written to a printer driver; there are excellent open-source tools available for manipulating Postscript.

This page describes setting up a driver on Windows that will produce Postscript although you will want to do something else with the Postscript other than sending it to another printer as described there.

antlersoft
  • 14,636
  • 4
  • 35
  • 55
  • Thanks for your response! Actually I had a doubt while going through your [suggested link](http://www.stat.tamu.edu/~henrik/GSPSprinter/GSPSprinter.html). Actually, people using my software might be using printer with any kind of Page Description Language(PDL) like ESC/PAGE(from Epson), PCL, PostScript, etc. So I was wondering that would all these printers be able to printout the output from GhostScript i.e. Rasterized image of the intended doc ? – mabicha Jun 09 '12 at 19:11
  • Once you've transformed the Postscript the way you want, you send it through the Ghostscript printer driver which converts the Postscript to a form acceptable to the printer. – antlersoft Jun 11 '12 at 15:03
1

I don't think you need a driver. Just use the standard Postscript driver provided with the WDK, adding .PPD and .INF files to name it and specify characteristics, and then put your code in a port monitor. Port monitors are considerably easier to build and maintain than print drivers.

Carey Gregory
  • 6,836
  • 2
  • 26
  • 47