2

I'm working on a program in C# to pause and get the total page count when printing, here is main code:

string wql = "SELECT * FROM Win32_PrintJob";
ManagementObjectCollection mos;
Dictionary<uint,short> checkedJobs = new Dictionary<uint,short>();

while (true)
{
      Thread.Sleep(SleepTime);
      try
      {
           mos = new ManagementObjectSearcher(wql).Get();
           if (mos != null && mos.Count > 0)
           {
                foreach (ManagementObject mo in mos)
                {
                    if (mo != null)
                    {
                        uint jobId = ProcessJob(mo);
                        if (!checkedJobs.ContainsKey(jobId))
                            checkedJobs.Add(jobId, 0);
                        }
                    }                        
                }
                // ...
           }
      }

It works fine with normal task.But in N-Up printing ,when I print more than one slides in one page(N Slides-In-One Page), it comes wrong, I can not get the right total count to print.

Is there anyone who ever meet this question~please help,many thanks

dayu
  • 21
  • 2
  • How are you getting the page count, and what is "wrong"? – Nick Westgate Nov 30 '17 at 20:24
  • The result is wrong means(Only in the mode of N-Up printing), for example,I print a ppt of 10 page;But I print the ppt of 5-in-1 mode(print 5 slides in one page).The total page should be 2, but it comes to 10. – dayu Dec 01 '17 at 07:33
  • And I get the total page by using JOB_INFO_2.TotalPages – dayu Dec 01 '17 at 07:44
  • You should really provide as much info as possible in your question. You don't tell us the apps you are testing with. Is it a Google Slides doc or something else? Which apps work and which cause problems? What are the results? – Nick Westgate Dec 01 '17 at 08:28
  • the app as the printing source is not the problem @NickWestgate,... coz the problem is obtaining the information while printing occured, he got the incorrect data in the end. – gumuruh Dec 31 '22 at 17:50
  • @gumuruh: The app and driver can be relevant. See my answer below, and my other answer I link to there. – Nick Westgate Dec 31 '22 at 23:38

1 Answers1

0

Your question is similar to another question (see my answer there and follow the link for more info) but perhaps it's different enough to warrant a different answer here.

Basically NUP is not supported by all print drivers. The application you're using may be checking the DEVMODE (or ignoring it) and handling NUP by itself rather than letting the Spooler handle it.

As I said in the other answer, the Windows page count can't be relied on for all apps and drivers. This might improve with the new XPS print system, but for old apps and drivers the only way to get a reliable page count is to parse the print spool file.

Nick Westgate
  • 3,088
  • 2
  • 34
  • 41
  • Can you please show me the detail how to parse the print spool file? Now I use the spool API to pause the print job; But I can not find a way to find out the real print count of the NUP job. – dayu Dec 04 '17 at 02:43
  • Thank you, I will have a try – dayu Dec 07 '17 at 10:03
  • We have tried many times, but we could still not get the right page count when printng N-up ppt.Have you ever solved this problem or Could you give us some guidance~Thank you – dayu Dec 15 '17 at 01:53
  • Thank you anyway,I will have a try. – dayu Dec 19 '17 at 10:02