如何获得打印页数 [英] How to get number of printed pages

查看:109
本文介绍了如何获得打印页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在为我们的班级实验室创建 c #windows应用程序,用于监控打印作业。我是这个领域的新手。我需要跟踪通过打印机打印的页数。 (系统有多台打印机,包括pdf打印机。)所以我的目标是从特定的打印机中获取成功打印的页数(份数*页数)。

是否有任何代码/帮助文件可用于此目的?请帮帮我。



提前谢谢

Hi,

I am creating a c# windows application for our class lab, for monitoring the print jobs. I am new to this field. I need to track the number of pages printed via a printer. (the system have multiple printers, including pdf printer.) So my aim is to get the number of successfully printed pages (number of copy * number of pages) from a specific printer.
Is there any code/helping document available for this purpose? Please help me.

Thanks in advance

推荐答案

我已经使用WMI解决了这个问题。这里有一个示例函数:



I have solved it by using WMI. a sample function is here:

public  void PausePrintJob()
        {
            string searchQuery = "SELECT * FROM Win32_PrintJob";
            ManagementObjectSearcher searchPrintJobs = new ManagementObjectSearcher(searchQuery);
            ManagementObjectCollection prntJobCollection = searchPrintJobs.Get();
            foreach (ManagementObject prntJob in prntJobCollection)
            { 
                string Document = prntJob.Properties["Document"].Value.ToString();
                
                string JobId = prntJob.Properties["JobId"].Value.ToString();
                string name = prntJob.Properties["Name"].Value.ToString();
                string PagePrinted = prntJob.Properties["PagesPrinted"].Value.ToString();
                string Status = prntJob.Properties["Status"].Value.ToString();
                string Totalpages = prntJob.Properties["TotalPages"].Value.ToString();
 
                string[] row = new string[] {Document,JobId,name,PagePrinted,Status,Totalpages};
                bool present = false;
                int i=0;
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    if (Convert.ToString(item.Cells["JobId"].Value) == JobId)
                    {
                        present = true;
                        break;
                    }
                    ++i;
                }
                if (present)
                {
                    dataGridView1.Rows.RemoveAt(i);
 
                }
                dataGridView1.Rows.Add(row);
 
            }
           
        }


参见 http://msdn.microsoft.com/en-us/library/system.printing.printqueue.aspx [ ^ ]。 Win32中还有许多可用的功能,但您需要使用P / Invoke来访问它们。 本白皮书 [ ^ ]可能对您有帮助。
See http://msdn.microsoft.com/en-us/library/system.printing.printqueue.aspx[^]. There are also many functions available in Win32 but you would need to use P/Invoke to access them. This White Paper[^] may help you.


这篇关于如何获得打印页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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