如何使用 C# 检查打印作业状态 [英] How to check a print job status with C#
问题描述
我正在通过从我的 C# 应用程序中执行命令行应用程序来打印 PDF 文件.现在我想知道什么时候打印这份工作.我希望会有某种我可以订阅并处理它的事件.但是我找不到.
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.
所以现在我求助于投票.并检查 PrinterSystemJobInfo 对象的 JobStatus.但就我而言,这要么给我 JobStatus = None 要么给我 JobStatus = Printing.
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
谁能告诉我如何使用 C# 可靠地检查打印作业状态?
Can someone tell me how to reliably check a print job status using C#?
推荐答案
这是 Microsoft 帮助和支持网站上的一篇很好的文章,内容涉及如何使用 Visual C# .NET 将原始数据发送到打印机.
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
好吧,您可以检查此示例中的 SendBytesToPrinter 方法;它将返回打印的结果.
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
但提供的第一个解决方案更可靠.
这篇关于如何使用 C# 检查打印作业状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!