2011-04-06 57 views
1

我通过在C#应用程序中执行命令行应用程序来打印PDF文件。现在我想知道这份工作何时印刷。我希望能有一些我可以订阅的事件,并处理它。但我找不到它。如何使用C#检查打印作业状态

所以现在我正在诉诸投票。并检查PrinterSystemJobInfo对象的JobStatus。但在我的情况下,这要么给我JobStatus = None或JobStatus =打印。

PrinterSystemJobInfo.JobStatus 

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

回答

0

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

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

好了,你可以检查此样品中SendBytesToPrinter方法;它会返回印刷物的结果。你

也可以使用贝娄代码:

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 

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

+0

同样的结果。这从“打印”到“具有管理权限的用户或某人已删除作业,必须重新提交。” 我只能说,如果作业已从队列中删除,作业已准备就绪。但我发现这是一个臭。顺便说一句,我每150毫秒轮询一次。我不断刷新PrintSystemJobInfo对象。 – Saab 2011-04-06 09:21:19

+0

您需要使用第一种解决方案。从微软支持网站访问这些链接, – 2011-04-06 09:25:18

相关问题