PainPoints PainPoints -4 years ago 198
C# Question

How to programmatically achieve editing of the spool file header of the normal windows print queue 'spool file' before it is sent to the printer?

How to intercept and change the windows 7 print spool file (.SPL) to add some additional information in the header like '@PJL SET NAME="PainPoint" ' before this file is sent to the printer during the execution of the print job?

The .SPL file partial extract from top is :

@PJL COMMENT DATE=02/08/2017
) HP-PCL XL;2;1;FXXPL2-1.0.0,WINNT-6.1,XPL2DRV-

Answer Source

Editing the spool file is obviously trivial. The trick is how to get access to the spool file.

I can think of a few ways offhand:

  1. Pause the print job after spooling, edit it, then release it. See my answer here. This is not trivial and you may need to resort to third-party software depending on time/effort available.
  2. Create a print driver or spooler component such as a port or language monitor to edit the file. (Thanks to Carey Gregory for the suggestion to use a language monitor). This is a big topic and you'll have to read a lot of documentation to figure out how to do it, but there is a sample (Pjlmon) in the WDK. Note that the newer V4 driver model for Windows 8/Server 2012 doesn't support these components.
  3. If you don't need to do this transparently you could set up RedMon (free) to call your app to edit the spool file. RedMon will then send it to the desired printer.

  4. VeryPDF has some similar commercial products with more capabilities.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download