How to print reports in submitted order using .NET

2019-08-30 03:46发布

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

2条回答
干净又极端
2楼-- · 2019-08-30 04:24

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

查看更多
做自己的国王
3楼-- · 2019-08-30 04:30

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

查看更多
登录 后发表回答