开发者

How to get Print Job Status using C#

I am able to print a document, but I d开发者_StackOverflow社区o not know how to get its status. I went through many resources (MSDN, Links for checking Job Status), but was not able to find an answer.

I actually want to get confirmation from the printer whether the document was successfully printed or not. Moreover, I am also interested if I can get error signal from printer, like if paper is jammed.

I have the Printer Name and Document name which I am sending for Print. Has anybody done some research in this area and can tell me how to accomplish this?


You might be able to use WMI for this. It provides several printing-related classes, including Win32_PrintJob.

This is untested, but something like this should get you started:

SelectQuery query = new SelectQuery("Win32_PrintJob");

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
using (ManagementObjectCollection printJobs = searcher.Get())
    foreach (ManagementObject printJob in printJobs)
    {
        // The format of the Win32_PrintJob.Name property is "PrinterName,JobNumber"
        string name = (string) printJob["Name"];
        string[] nameParts = name.Split(',');
        string printerName = nameParts[0];
        string jobNumber = nameParts[1];
        string document = (string) printJob["Document"];
        string jobStatus = (string) printJob["JobStatus"];

        // Process job properties...
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜