Can I use WMI to read a printer spool file

Viewed 534

My client has an old DOS-based application which sends formatted output to a printer. I have disabled printing so spooled files remain in the print queue. I would like to pick up these spool files and convert them to PDF format (then ideally delete them). Is this possible using WMI?

BTW I cannot change anything within the application which produces the printed output.

I would like to do this as part of an existing Visual Foxpro utility which I support.

2 Answers

The formatted output of the application will be ASCII text with embedded Epson or PCL printer codes. A Windows virtual PDF printer (or other printer drivers) doesn’t support such data stream. You would have to use the Generic Text Only printer driver and save the output to file. Or a DOS-to-Windows print processor like DOSprn, or a DOS emulator like vDos, that converts the ASCII text for a Windows printer driver.

There are many complications, but most of them are covered here. In particular see:

  • Force JobID in Spoolfile names
  • When is RAW used?

Depending on the application, driver, and other factors, the format of the spool files will be EMF, XPS or a "raw" PDL like PostScript, PCL, PCL6 etc. EMF is a bit old in the tooth now, but you can find modern components to render most PDLs. If you can get the driver you're using to spool to PDF then you're done.

Since the DOS application successfully prints to an HP 4200 (which supports these languages: HP GL/2, HP PJL, PCL 5E, PCL 6, PostScript 3), the spool file is likely to be ASCII with control codes or PCL escape codes. You should open the spool file in a hex editor and have a look. They are usually stored in "C:\Windows\System32\spool\PRINTERS" as SPL files.

You might be able to use GhostScript depending on which licences you're ok with. E.g. for PCL to PDF see this (old) question and its answers - search for more recent ones.

Other commercial options include Aspose for EMF to PDF. These are the kinds of tools you need to seek out and evaluate for your particular use cases.

WMI can delete print jobs. E.g. on the command line:

wmic printjob where jobid=<jobnumber> delete
Related