Can I use WMI to read a printer spool file

836 views Asked by At

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.

3

There are 3 answers

2
Jos Schaars On

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.

1
Nick Westgate On

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
0
Alan B On

If it's a HP the files are (as everyone else above has said) in PCL. There is a command line utility here that converts PCL to PDF. To quote:

This page offers two almost identical utilities that create PDF output from PCL "print files." Both use GhostPCL by Artifex (released under the GNU General Public License) as the engine that performs the conversion.

So you could do it from Visual FoxPro by building a command line to run the EXE with the relevant parameters and executing it with (for example) Windows Scripting Host:

lcExe = "full\path\to\winpcltopdf.exe"
lcCommandLine = "myinputfile.pcl myoutputfile.pdf"
loWshShell = CreateObject("WScript.Shell")
lnProcessReturnCode = loWshShell.Run(lcExe + " " + lcCommandLine, 1, .t.)