问题
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?
回答1:
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
回答2:
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...
}
回答3:
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
来源:https://stackoverflow.com/questions/45700836/check-physical-print-job-success