0

Our VB WinForms application prints a series reports using the standard PrintDocument object, some with multiple pages. My client has pointed out the the hard copy reports are not printed in the correct order. When I debug the code, I can verify the reports are generated in the correct order, but when I inspect the print queue the reports are not displayed in the order they were submitted. When I sort the queue by Submitted (date-time), the correct order of reports is shown.

Is there a way to set the print queue from VB.NET so that multiple reports are queued and printed in date-time order? Or am I fishing in the wrong hole?

TIA

ron tornambe
  • 10,452
  • 7
  • 33
  • 60
  • How are you printing them, is there code doing this work? – KreepN Oct 18 '12 at 18:59
  • I am using the standard PrintDocument object and there is quite a lot of code. When I direct printing to a PDF print driver, the correct order is maintained. I can post some code if you think it will help. – ron tornambe Oct 18 '12 at 19:10

2 Answers2

2

Turn off print spooling on the printer, so the application prints directly to the printer. This is on the advanced tab of the printer properties.

enter image description here

John Koerner
  • 37,428
  • 8
  • 84
  • 134
2

This is an effect of print spooling. Items are not added to the print queue until they finish spooling so they will queue in the order that they finish spooling rather than the order in which they are printed. Large files (with images, etc) take longer to spool than smaller ones so it is possible for items printed later to finish spooling first if they spool more quickly. You can disable print spooling (as has been suggested) but this can make printing cumbersome since all applications will then block on print jobs until they are finished rather than letting the spool do the work.

An alternative may be to query the print queue in your own application - don't send your next print job until you get confirmation that it has finished spooling (if spooling is being used). This gets around the clumsy solution of both forcing your users to change system settings and forcing other programs to not have access to the convenience of the print spool. See :

PrintQueue Class

W̶i̶t̶h̶ ̶t̶h̶e̶ ̶a̶b̶o̶v̶e̶ ̶y̶o̶u̶ ̶c̶a̶n̶ ̶p̶r̶o̶g̶r̶a̶m̶a̶t̶i̶c̶a̶l̶l̶y̶ ̶c̶h̶a̶n̶g̶e̶ ̶t̶h̶e̶ ̶s̶p̶o̶o̶l̶/̶d̶i̶r̶e̶c̶t̶ ̶s̶e̶t̶t̶i̶n̶g̶ ̶(̶r̶a̶t̶h̶e̶r̶ ̶t̶h̶a̶n̶ ̶d̶o̶i̶n̶g̶ ̶i̶t̶ ̶v̶i̶a̶ ̶p̶r̶i̶n̶t̶e̶r̶ ̶p̶r̶o̶p̶e̶r̶t̶i̶e̶s̶ ̶m̶a̶n̶u̶a̶l̶l̶y̶)̶ ̶o̶r̶, (Nevermind, that property is read-only.) probably better, use something like

PrintQueue.GetPrintJobInfoCollection

to monitor the queue when sending out print jobs.

The above is supported in Server2008 and VistaSP2 and above. For XP and earlier you may need to follow something more like :

How to query the print queue on Windows

perhaps by listening for :

WM_SPOOLERSTATUS

Community
  • 1
  • 1
J...
  • 30,968
  • 6
  • 66
  • 143
  • @rontornambe of course, the easy way may be just to collate your reports into a single document, in the correct order, before printing and then just do it all as one print job... – J... Oct 19 '12 at 01:14
  • "PrintQueue Class: With the above you can programatically change the spool/direct setting" I would be glad to know how this is done: http://stackoverflow.com/questions/33347791/how-to-change-the-spool-direct-print-setting-via-code – D_Bester Oct 26 '15 at 14:08
  • @D_Bester My bad. Updated the answer. You may be able to do it with WinAPI calls (I'm not sure) but as above the better answer is to serialize the print calls yourself rather than switching to direct mode as that will kill the performance of all other applications that use printers - this can make your users very angry when they find out that it's your application that has caused MS Word to hang for five minutes while it waits for the shared office printer to finally get around to printing their document! – J... Oct 26 '15 at 15:35