0

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!

Condra963
  • 27
  • 5
  • This thread is also running on MSDN: https://social.msdn.microsoft.com/Forums/en-US/d8d07a54-f74a-44c9-a18f-6878782b4961/print-spool-api-number-of-copies?forum=csharpgeneral – Condra963 Jun 29 '16 at 16:28

2 Answers2

2

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.

Nick Westgate
  • 3,088
  • 2
  • 34
  • 41
  • I've been developing Windows print drivers for years, and I will testify that all MS Office products are some of the most badly behaved printing applications out there. They all use weird techniques almost no other apps use. – Carey Gregory Jul 17 '16 at 05:20
1

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?

Condra963
  • 27
  • 5
  • It doesn't work to post your comments as an answer, which is what you did. The person you're trying to address probably has no idea you posted this. Post a comment on his answer if you still need to ask. – Carey Gregory Jul 17 '16 at 05:22
  • 1
    And to answer your question, catching the DocumentProperties calls would require some sort of code injection. Those calls go from the application to the GDI to the print driver, and you would have to intercept them. Obviously, that's an expensive, high risk option. As Nick Westgate said in his answer, your best data is going to be the spool file. Parsing that is no cakewalk either. – Carey Gregory Jul 17 '16 at 05:28
  • Yes, if you can install on every client you could try hooking the DocumentProperties API with DLL injection, but IIRC you might still run into problems with drivers using non-standard DEVMODEs. Windows GDI printing is a mess, and the new XPS path is not talked about much. – Nick Westgate Jul 17 '16 at 22:10
  • Can you give me an example of how to get this info (the real number of copies in a Word file) from DEVMODE record in the SPL file. Now I got dmCopies from Jobinfo_2's DEVMODE, but this way you talking I don't know do it. – karelp90 Oct 31 '17 at 14:12
  • @karelp90: That looks like a question. Who are you asking? Condra963 who hasn't logged in since June? This should be posted as its own question with similar tags to the question above, and then those who follow the tags will be notified. Whether they answer will depend on whether they feel like spending precious moments of their life typing an answer that will probably never get accepted or even upvoted. Use SO wisely. Is your question related to [this](https://stackoverflow.com/q/46533312/313445)? – Nick Westgate Oct 31 '17 at 20:45
  • @Condra963 did you figure out the solution about dmCopies from a word document??? I have the same problem – karelp90 Nov 02 '17 at 14:06
  • @karelp90 It is just a bug, possible there are other ways to find the number of copies, i don't know how you are doing it at the moment? You can always send me a mail or message here on stackoverflow. – Condra963 May 03 '18 at 10:52