1

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#?

Saab
  • 981
  • 3
  • 11
  • 34

1 Answers1

0

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.

Farzin Zaker
  • 3,578
  • 3
  • 25
  • 35
  • Same result. This goes from "Printing" to "The user or someone with administration rights to the queue has deleted the job. It must be resubmitted." I could just say if the job is removed from the queue the job is ready. But I find that a smelly. By the way, I'm polling every 150ms. And I keep refreshing the PrintSystemJobInfo object. – Saab Apr 06 '11 at 09:21
  • You need to use first solutions. visit those link from microsoft support website, – Farzin Zaker Apr 06 '11 at 09:25