Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Print Job Status using C#

Tags:

c#

.net

printing

I am able to print a document, but I do 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?

like image 710
SharpUrBrain Avatar asked Aug 05 '11 10:08

SharpUrBrain


1 Answers

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...
    }
like image 166
Lance U. Matthews Avatar answered Oct 08 '22 12:10

Lance U. Matthews