如何使用C#检查打印作业状态

时间:2011-04-06 08:55:21

标签: c# printing

我通过在C#应用程序中执行命令行应用程序来打印PDF文件。现在我想知道什么时候打印这份工作。我希望会有一些我可以订阅的事件,并处理它。但我找不到它。

所以现在我正在求助于民意调查。并检查PrinterSystemJobInfo对象的JobStatus。但在我的情况下,这或者给我JobStatus = None或JobStatus = Printing。

PrinterSystemJobInfo.JobStatus

有人能告诉我如何使用C#可靠地检查打印作业状态吗?

1 个答案:

答案 0 :(得分:0)

以下是Microsoft帮助和支持网站上的一篇很好的文章,该文章涉及如何使用Visual C#.NET将原始数据发送到打印机。

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

好吧,您可以查看此示例中的SendBytesToPrinter方法;它会返回印刷品的结果。

您也可以使用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 

但提供的第一个解决方案更可靠。