有没有办法检查打印过程是否成功? [英] Is there a way to check if a printing process was successful?

查看:173
本文介绍了有没有办法检查打印过程是否成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要打印票证的应用程序.每张票必须是唯一的.该应用程序是Windows窗体,完全用c#编写.对于我们的应用程序,我们使用Samsung ML-2525激光单色打印机.

I have an application where I need to print a ticket. Each ticket must be unique. The application is windows forms and written entirely in c#. For our application we're using Samsung ML- 2525 laser monochromatic printers.

基本上,流程如下,操作员选择一个产品/票(唯一),然后按下执行2件事的按钮:

The flow is basically the following, the operator picks a product/ticket (which is unique) and then it presses a button that does 2 things:

  1. 连接到数据库并更新使用的产品
  2. 打印票证(使用System.Drawing和GDI +完成此操作)

由于某些原因,需要打印的图像有时不发送到打印机.这种情况很少见,但确实发生了.

For some reason, every once in a while, the image that needs to be printed is not sent to the printer. It's a rare case, but it happens.

我尝试使用Win32_Printer( http://msdn.microsoft. com/en-us/library/Aa394363 ),但无法获取当前打印机的状态(在线,离线,低碳粉,卡纸等).我只能检查打印机是否存在以及纸张尺寸是否正确安装.我尝试了类似于以下内容的代码,但没有成功

I tried to connect to the printer using Win32_Printer ( http://msdn.microsoft.com/en-us/library/Aa394363 ) but I can't get to get the current printer's state (online, offline, low toner, paper jam, etc). I can only check if the printer exists and that the paper size is installed correctly. I tried code similar to the following but it didn't work

    private string MonitorPrintJobWmi()
    {
        var jobMessage = String.Empty;
        var scope = new ManagementScope(ManagementPath.DefaultPath);
        scope.Connect();

        var selectQuery = new SelectQuery { QueryString = @"select *  from Win32_PrintJob" };

        var objSearcher = new ManagementObjectSearcher(scope, selectQuery);
        var objCollection = objSearcher.Get();

        foreach (var job in objCollection)
        {
            if (job != null)
            {
                jobMessage += String.Format("{0} \r\n", job["Name"].ToString());
                jobMessage += String.Format("{0} \r\n", job["JobId"].ToString());
                _jobId = Convert.ToInt32(job["JobId"]);
                jobMessage += String.Format("{0} \r\n", job["JobStatus"].ToString());
                jobMessage += String.Format("{0} \r\n", job["Status"].ToString());
            }
        }
        return jobMessage;
    }

我尝试获取打印机的API,但无法获取它.顺便说一下,打印机的软件确实在Windows工具栏中指示了不同的错误.

I tried to get an API for the printer but I couldn't get a hold of it. By the way, the printer's software do indicate different errors in the windows toolbar.

我的问题是,是否有人可以引导我正确地连接打印机,并检查打印是否成功.

My question is if anyone can lead me in the right direction as to how to connect to a printer and check if printing was successful.

另外,如果有人知道我可以在其中完成此操作的某些其他特定打印机(即更改硬件),这将很有帮助.

Also, it would be helpful if someone know of some other specific printer in which I may accomplish this ie, changing hardware.

谢谢

推荐答案

要获取本地计算机上的打印队列列表,请尝试使用PrintServer的

To get a list of print queues on the local machine, try PrintServer's GetPrintQueues method.

一旦您拥有关联的 PrintQueue 对象的实例对于相关的打印机,您可以使用它来访问打印机的状态(IsOffline,IsPaperOut等).此外,您还可以使用它来获取给定队列中的作业列表(

Once you have an instance of the PrintQueue object associated with the relevant printer, you can use it to access the printer's status (IsOffline, IsPaperOut, etc.). Also, you can use it to get a list of the jobs in the given queue (GetPrintJobInfoCollection) which then will allow you to get job-specific status information (IsInError, IsCompleted, IsBlocked, etc.).

希望这会有所帮助!

这篇关于有没有办法检查打印过程是否成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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