开发者

How to check a print job status with C# [duplicate]

开发者 https://www.devze.com 2023-02-22 23:17 出处:网络
This question already has an answer here: How to get Print Job Status using C# (1 answer) Closed 5 years ago.
This question already has an answer here: How to get Print Job Status using C# (1 answer) Closed 5 years ago.

I'm printing a PDF file by executing a commandline application from within my C# application. Now I wanna开发者_运维知识库 know when this job is printed. I was hoping there would be some kind of event I could subscribe to, and handle it. But I couldn't find it.

So now I'm resorting to polling. And checking the JobStatus of a PrinterSystemJobInfo object. But in my case this either gives me JobStatus = None or JobStatus = Printing.

PrinterSystemJobInfo.JobStatus

Can someone tell me how to reliably check a print job status using C#?


Here is a good article in Microsoft help and support web site, which concerns how to send raw data to a printer by using Visual C# .NET.

http://support.microsoft.com/kb/322091

Well, you can check the SendBytesToPrinter method in this sample; it will return the result of the printing things.

Also you can use Bellow Code :

public enum PrintJobStatus
// 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 

but the first solution provided is more reliable.

0

精彩评论

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