Printer spooler api number of copies

2019-09-06 05:45发布

问题:

I really could use some help, this is a question that alot of people are asking on the internet. I have different setups, tried different ways of testing, it's very frustrating.

First setup:

  • local printers

  • local running code

  • print from pdf or notepad: SUCCES (number of copies are 2)

  • print from word: FAILED (numberof copies is 1)

Second setup:

  • local printers that are shared

  • local running code

  • print from other computer to shared printers

  • number of copies isalways 1

Sowhat is everyone missing? What happens that some fields are missing while the printer still should know what to print? What does word that also happen when you print from another computer? Can someone tell me why somethings in windows are so terrible? Everythingshould pass the spooler, sowhy isthedata wrong?

Kinds regards!

回答1:

A printer prints sheets and pages, so copies is converted to pages at some stage.

The notification data you get depends on both the application that is printing and the system and driver components handling the spooling and rendering. In my experience the data cannot be relied on, and the best data is obtained by parsing the spool file. This may or may not contain the number of copies.

Word has had the "copies problem" for a long time. There was a patch to supposedly fix this, but another opinion is that it's because it uses an unusual way of printing. I'll quote some of the link contents here:

With the infamous Word Copy Count bug… the dmCopies filed is 1 in the SHD. The correct value is found in the DEVMODE record in the SPL file (if it's an EMF spool).

The only other way i found was to monitor the PrintedPages field of the JOB_INFO_2 structure, when the job has been sent to the printer, and see if it is a multiple of TotalPages.

[...]

What happens is not a Word bug, but a Windows bug. Word calls startDoc always with copies set to 1. After that calls DocumentProperties and makes the change in dmCopies and calls ResetDC to make the update. It is a strange way of printing but not wrong. The problem is that the shd file and printer_info is not updated with this information, just keeps the Devmode info set on the StartDoc call.

But the call to the ResetDC generating a new DevMode is kept on the SPL file. You can get that info too if you hook DocumentProperties API calls.



回答2:

Thank you for the answer. Is there a way of catching the document properties when they change?

The JOB_INFO_2 structure does have the same total_pages as pages_printed. So that is not a solution.

The SPL File does contain the QTY for the printer i tested on which is correct. BUT we tested on a lot of printers and we see the QTY is not Always set. So not a 100% solution. But already a good fallback.

So if i can catch the document properties without calling the SPL file that would be wonderful because i guess that's where everything is correct. Isn't it?