4
votes

I am trying to print several PDF files using some Pdf reader launched using shellExecute in Delphi 2007.

Reliability of such an approach may not be very good because the actual printing can fail due to several reasons. I am wondering if there is a way for my program to know if or when the file is actually send to the print spooler?

1

1 Answers

6
votes

To monitor printer jobs, you can use the FindFirstPrinterChangeNotification API call with PRINTER_CHANGE_WRITE_JOB passed in the fdwFilter parameter. This will let you know every time job data was written to the printer via FindNextPrinterChangeNotification.

When you're done, don't forget to call FindClosePrinterChangeNotification to close all the handles and clean up.

The use can get rather complicated. Dr. Peter Below of TeamB posted a unit that has wrappers around this a while back to the old Borland Code Central pages (which are now available at the Embarcadero site) in a unit called PBPrintersMonitorU.pas. You can find it here, if you have an EDN (Embarcadero Developers Network) account.