簡體   English   中英

如何使用 system.printing 獲取打印頁數?

[英]How to get number of printed pages using system.printing?

我正在編寫一個簡單的應用程序,它將監控我每天打印的頁數。 我正在使用 .Net,我發現 System.printing 命名空間似乎易於使用。

下面是我的代碼。

public static void NumberOfPagesPrintedTest()
    {
        PrintServer ps = new PrintServer();

        PrintQueueCollection printQueues = ps.GetPrintQueues();

        foreach (var item in printQueues)
        {
            //if (item.QueueStatus == PrintQueueStatus.Printing)
            //{
                item.Refresh();
                PrintJobInfoCollection coll = item.GetPrintJobInfoCollection();
                if (coll != null)
                {
                    foreach (var jobinfo in coll)
                    {
                        Console.WriteLine(jobinfo.NumberOfPages + " printed " + jobinfo.NumberOfPagesPrinted + " printing " + jobinfo.IsPrinting + " printed " + jobinfo.IsPrinted);
                    }
                }
            //}
        }
    }

但是在打印過程中它顯示了打印的頁數,但是在一些頁面已經打印之后它不會改變並且jobinfo.NumberOfPagesPrinted總是等於0。如何獲得實際打印的頁數以及如何找出有多少頁如果打印機因某種原因停止,則打印。

下面的編寫方法如何獲取頁數:-

public static int PrintedPageCount(PrintDocument printDocument)
{
    int counter = 0;
    printDocument.PrintController = new PreviewPrintController();
    printDocument.PrintPage += (sender, e) => counter ++;
    printDocument.Print();
    return counter;
}

您需要刷新您的工作(使用job.refresh() ),直到IsSpooling標志等於false

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM