Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Posted
Updated 17-May-19 9:10am

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

C#
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);
 
            }
           
        }
 
Share this answer
 
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.
 
Share this answer
 
Comments
Little@Knight 30-Jun-16 0:02am    
Is there any way to get number of copies before printing?
Richard MacCutchan 30-Jun-16 3:34am    
No idea, you would need to follow the links above to find out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900