How to get Print Job Status using C#

后端 未结 3 1043
再見小時候
再見小時候 2020-12-01 18:59

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 answ

相关标签:
3条回答
  • 2020-12-01 19:45

    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 讨论(0)
  • 2020-12-01 20:04

    there are samples online... google "sending PJL commands in c#" (PJL stands for printer job language)

    codeproject Reading Data Directly from the Printer is a nice article/sample to start with

    0 讨论(0)
  • 2020-12-01 20:04

    You can try this Code also

    // Check for possible trouble states of a print job using the flags of the JobStatus property

    internal static void SpotTroubleUsingJobAttributes(PrintSystemJobInfo theJob)
    {
    
    if ((theJob.JobStatus & PrintJobStatus.Blocked) == PrintJobStatus.Blocked)
    {
        Console.WriteLine("The job is blocked.");
    }
    if (((theJob.JobStatus & PrintJobStatus.Completed) == PrintJobStatus.Completed)
        || 
        ((theJob.JobStatus & PrintJobStatus.Printed) == PrintJobStatus.Printed))
    {
        Console.WriteLine("The job has finished. Have user recheck all output bins and be sure the correct printer is being checked.");
    }
    if (((theJob.JobStatus & PrintJobStatus.Deleted) == PrintJobStatus.Deleted)
        || 
        ((theJob.JobStatus & PrintJobStatus.Deleting) == PrintJobStatus.Deleting))
    {
        Console.WriteLine("The user or someone with administration rights to the queue has deleted the job. It must be resubmitted.");
    }
    if ((theJob.JobStatus & PrintJobStatus.Error) == PrintJobStatus.Error)
    {
        Console.WriteLine("The job has errored.");
    }
    if ((theJob.JobStatus & PrintJobStatus.Offline) == PrintJobStatus.Offline)
    {
        Console.WriteLine("The printer is offline. Have user put it online with printer front panel.");
    }
    if ((theJob.JobStatus & PrintJobStatus.PaperOut) == PrintJobStatus.PaperOut)
    {
        Console.WriteLine("The printer is out of paper of the size required by the job. Have user add paper.");
    }
    
    if (((theJob.JobStatus & PrintJobStatus.Paused) == PrintJobStatus.Paused)
        || 
        ((theJob.HostingPrintQueue.QueueStatus & PrintQueueStatus.Paused) == PrintQueueStatus.Paused))
    {
        HandlePausedJob(theJob);
        //HandlePausedJob is defined in the complete example.
    }
    
    if ((theJob.JobStatus & PrintJobStatus.Printing) == PrintJobStatus.Printing)
    {
        Console.WriteLine("The job is printing now.");
    }
    if ((theJob.JobStatus & PrintJobStatus.Spooling) == PrintJobStatus.Spooling)
    {
        Console.WriteLine("The job is spooling now.");
    }
    if ((theJob.JobStatus & PrintJobStatus.UserIntervention) == PrintJobStatus.UserIntervention)
    {
        Console.WriteLine("The printer needs human intervention.");
    }}
         //end SpotTroubleUsingJobAttributes
    
    0 讨论(0)
提交回复
热议问题