Is there a better way to get the page count from a PrintDocument than this?

前端 未结 3 527
我在风中等你
我在风中等你 2021-01-12 07:55

This is the best I\'ve come up with:

public static int GetPageCount( PrintDocument printDocument )
{
    printDocument.PrinterSettings.PrintFileName = Path.G         


        
3条回答
  •  青春惊慌失措
    2021-01-12 08:23

    Check - http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.querypagesettings.aspx

    There is a PrintDocument.QueryPageSettings Event that could be handled. If handled, it is called before each PrintDocument.PrintPage event. So you can put a counter there to count the pages. This way you could avoid a two pass (one pass to print the doc to file for counting the pages and second pass for the actual job printing).

    The URL above has some example code for a counter also.

    Hope this helps

提交回复
热议问题