如何使用 C# 获取打印作业状态 [英] How to get Print Job Status using C#

查看:42
本文介绍了如何使用 C# 获取打印作业状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以打印文档,但不知道如何获取其状态.我浏览了许多资源(MSDN检查作业状态的链接),但无法找到答案.

I am able to print a document, but I do not know how to get its status. I went through many resources (MSDN, Links for checking Job Status), but was not able to find an answer.

我实际上想从打印机那里确认文档是否成功打印.此外,我也很感兴趣是否可以从打印机获得错误信号,例如卡纸.

I actually want to get confirmation from the printer whether the document was successfully printed or not. Moreover, I am also interested if I can get error signal from printer, like if paper is jammed.

我有要发送用于打印的打印机名称和文档名称.有没有人在这方面做过一些研究,可以告诉我如何做到这一点?

I have the Printer Name and Document name which I am sending for Print. Has anybody done some research in this area and can tell me how to accomplish this?

推荐答案

您或许可以为此使用 WMI.它提供了几个打印相关类,包括Win32_PrintJob.

You might be able to use WMI for this. It provides several printing-related classes, including Win32_PrintJob.

这是未经测试的,但像这样的东西应该会让你开始:

This is untested, but something like this should get you started:

SelectQuery query = new SelectQuery("Win32_PrintJob");

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
using (ManagementObjectCollection printJobs = searcher.Get())
    foreach (ManagementObject printJob in printJobs)
    {
        // The format of the Win32_PrintJob.Name property is "PrinterName,JobNumber"
        string name = (string) printJob["Name"];
        string[] nameParts = name.Split(',');
        string printerName = nameParts[0];
        string jobNumber = nameParts[1];
        string document = (string) printJob["Document"];
        string jobStatus = (string) printJob["JobStatus"];

        // Process job properties...
    }

这篇关于如何使用 C# 获取打印作业状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆