How to print reports in submitted order using .NET

帅比萌擦擦* 提交于 2019-12-25 02:00:34

问题


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


回答1:


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.




回答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



来源:https://stackoverflow.com/questions/12961810/how-to-print-reports-in-submitted-order-using-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!