3

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.

Mart
  • 31
  • 1
  • You can get the job id from WMI. The files are just sitting there on disk waiting to be read. You just need something that understands whatever format they're in. – Nick Westgate Jan 18 '21 at 23:39
  • Thanks Nick. I can see the files but can't read them. The printer queue that I used is a PDF creator and hoped then that the spool file might be in PDF format, but I cannot open it with a PDF reader. Any further suggestions very welcome. – Mart Jan 19 '21 at 13:32

3 Answers3

1

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.

  • Thanks Jos. I should have mentioned that the client has told me that the only printer they have been able to get to work with the application is an HP 4200. – Mart Jan 25 '21 at 12:12
  • That implies the application uses PCL codes to format the output. Most laser printers (and of course those of HP) still support PCL input. But other printers (and virtual ones) don’t accept that. Just install vDos, its internal print processor supports most PCL commands. – Jos Schaars Jan 25 '21 at 19:18
0

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
Nick Westgate
  • 3,088
  • 2
  • 34
  • 41
  • Thanks Nick. I should have mentioned that the client has told me that the only printer they have been able to get to work with the application is an HP 4200. – Mart Jan 25 '21 at 12:11
0

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.)   
Alan B
  • 4,086
  • 24
  • 33