2011-04-06 195 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

相關問題