2

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 :

%-12345X@PJL SET STRINGCODESET=UTF8
@PJL COMMENT DATE=02/08/2017
@PJL ENTER LANGUAGE=PCLXL
) HP-PCL XL;2;1;FXXPL2-1.0.0,WINNT-6.1,XPL2DRV-6.9.1.1
?X???........
PainPoints
  • 461
  • 8
  • 20

1 Answers1

1

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.

Community
  • 1
  • 1
Nick Westgate
  • 3,088
  • 2
  • 34
  • 41
  • Well I am a java/scala background, what do you suggest? The actual task is to include additional PJL headers to the spool file and then send to the printer. – PainPoints Feb 09 '17 at 04:27
  • Since you imply you want to avoid native coding, I would suggest trying option 3 first. – Nick Westgate Feb 09 '17 at 04:36
  • I setup RedMon but it works to forward to another printer/output only. I think I would work on Visual C++ or sth else, is it absolutely achievable to pause a print job after spooling, edit it and then release? I need to do achieve this functionality for only 1 printer but not on other printers which are working normally. – PainPoints Feb 10 '17 at 06:24
  • There are other port monitors that I think you could use, but they are commercial. VeryPDF have one amongst their many products - it's [mentioned here](http://www.verydoc.com/blog/intercepting-data-sent-to-a-windows-printer.html). Another one [is here](http://www.alphatronics.net/AVPMon.html). Or you could write your own port monitor (option 2) using the Windows SDK monitor sample as a base, or perhaps the RedMon source. But yes, option 1 is definitely possible. [Here is some software](http://www.papercut.com/products/free-software/) that uses this technique - my other answer links to samples. – Nick Westgate Feb 10 '17 at 09:12
  • This is what language monitors are for. https://msdn.microsoft.com/en-us/windows/hardware/drivers/print/language-monitors – Carey Gregory Mar 01 '17 at 03:10
  • @CareyGregory: Thanks. Why don't you expand that into an answer? ; - ) – Nick Westgate Mar 01 '17 at 20:46
  • Eh, not enough time. Why don't you just add a note about it in your answer. – Carey Gregory Mar 01 '17 at 22:24
  • @CareyGregory: Done. But I remembered that monitors aren't supported for V4 drivers. Also, I'm not sure how to add a language monitor to an existing printer. – Nick Westgate Mar 01 '17 at 23:48
  • Heh, yeah, I didn't want to have to explain the v4 stuff, installation, etc. I think merely pointing out the option is sufficient because it is a lot of work just to understand these components and get them working. – Carey Gregory Mar 02 '17 at 00:55