1

the task is to create a log of all .pdf print jobs a user has sent from a specific computer. Once the file gets printed, I want to open the file (programmatically) and extract some information from it.

I know that I can use the Print Spooler API to retrieve a list of all printers and then use GetJob() to find information about a new job. The JOB_INFO structure does not contain the full file path, however, which would be what I need to open the file, however. This makes sense since I can also send a print job directly from any program without having any actual file at all.

Is there a way of hooking into the default print dialog? Or maybe the "Print..." - button in the windows explorer? Not really sure where to start looking, I will be glad for any hint I can get.

Ideally in C#, but any language will be fine.

Stefan Lutz
  • 161
  • 6

1 Answers1

1

The idea with the Print Monitor sounded good, but I've gone another (possibly simpler) way now.

  1. Enumerate the new .lnk files in the "Recent" - directory. (Environment.SpecialFolder)
  2. Analyze the filename to check if it is a .pdf file.
  3. If so, enumerate the print jobs of all printers to see if there is a job whose filename matches the name of the recently opened file.
  4. If there is such a job, follow the .lnk to the destination. This is the printed file.

This relies on the fact that a .pdf file has to opened with a PDF viewer before it will be printed. The method requires to check all print jobs and recent files regularily, however, which can be rather performance intensive.

Community
  • 1
  • 1
Stefan Lutz
  • 161
  • 6