从Win32_PrintJob获取打印副本详细信息和总页数

时间:2018-11-12 15:10:41

标签: c# windows winforms printing

每当请求打印文档时,我都会使用以下代码来获取打印作业详细信息。它不返回print copytotal no. of pages printed

我发现,当我选择“ OneNote”作为打印机来打印文档时,它会正确返回total no. of pages printed,即文档总页数*打印副本。

 // Query to get all the queued printer jobs.
                searchQuery = "SELECT * FROM Win32_PrintJob";
                // Create an object using the above query.
                searchPrintJobs = new ManagementObjectSearcher(searchQuery);
                // Fire the query to get the collection of the printer jobs.
                prntJobCollection = searchPrintJobs.Get();

                // Look for the job you want to delete/cancel.
                if (prntJobCollection.Count > 0)
                {
                    foreach (ManagementObject prntJob in prntJobCollection)
                    {
                        UInt32 TotalPages = (UInt32)prntJob.Properties["TotalPages"].Value;
                        JobId = (UInt32)prntJob.Properties["JobId"].Value;
                        UInt32 PagesPrinted = (UInt32)prntJob.Properties["PagesPrinted"].Value;
                        string Caption = (string)prntJob.Properties["Caption"].Value;
                        string Color = (string)prntJob.Properties["Color"].Value;
                        string DataType = (string)prntJob.Properties["DataType"].Value;
                        string Description = (string)prntJob.Properties["Description"].Value;
                        string Document = (string)prntJob.Properties["Document"].Value;
                        string DriverName = (string)prntJob.Properties["DriverName"].Value;
                        string ElapsedTime = (string)prntJob.Properties["ElapsedTime"].Value;
                        HostPrintQueue = (string)prntJob.Properties["HostPrintQueue"].Value;
                        string JobStatus = (string)prntJob.Properties["JobStatus"].Value;
                        string Name = (string)prntJob.Properties["Name"].Value;
                        string Notify = (string)prntJob.Properties["Notify"].Value;
                        Owner = (string)prntJob.Properties["Owner"].Value;
                        UInt32 PaperLength = (UInt32)prntJob.Properties["PaperLength"].Value;
                        string PaperSize = (string)prntJob.Properties["PaperSize"].Value;
                        UInt32 PaperWidth = (UInt32)prntJob.Properties["PaperWidth"].Value;
                        string PrintProcessor = (string)prntJob.Properties["PrintProcessor"].Value;
                        UInt32 Priority = (UInt32)prntJob.Properties["Priority"].Value;
                        UInt32 Size = (UInt32)prntJob.Properties["Size"].Value;
                        string Status = (string)prntJob.Properties["Status"].Value;
                        UInt32 StatusMask = (UInt32)prntJob.Properties["StatusMask"].Value;
                        string TimeSubmitted = (string)prntJob.Properties["TimeSubmitted"].Value;}}

我还试图从JOB_INFO_2结构中检索这些详细信息,但无法将其实现为explained here.

0 个答案:

没有答案