wpf 对于物理打印机,.CurrentPrintTicket.PageMediaSize.PageMediaSizeName的结果始终为ISOA4

elcex8rz  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(93)

当我在c#中使用PrintServer类时,我会得到打印队列和打印作业,但是对于iR-ADVC 3525或其他物理打印机,printJob.HostingPrintQueue.CurrentJobSettings.CurrentPrintTicket.PageMediaSize.PageMediaSizeName.ToString()的结果总是ISOA4。即使我定义了ISOA3或其他格式。
我尝试将物理打印机首选项设置为A3。所以printJob.HostingPrintQueue.CurrentJobSettings.CurrentPrintTicket.PageMediaSize.PageMediaSizeName.ToString()ISOA3
但是,我希望从打印spokesman而不是从首选项中检索信息
我试过使用Microsoft Print to PDF(用于创建PDF的虚拟打印机),当我定义它时,我得到了ISOA 3格式。
下面是我迭代打印作业的代码:

public void CatchJobs()
 {
     PrintServer printServer = new PrintServer();
     PrintQueueCollection printQueues = printServer.GetPrintQueues();
     foreach (PrintQueue printQueue in printQueues)
     {
         printQueue.Refresh();
         if (printQueue.GetPrintJobInfoCollection() != null)
         {
             PrintJobInfoCollection printJobs = printQueue.GetPrintJobInfoCollection();

             foreach (PrintSystemJobInfo printJob in printJobs)
             {
                 Job job = new Job(printJob);
                 if (printJob.JobStatus.HasFlag(PrintJobStatus.Printed) && !Jobs.Contains(job))
                 {
                     lock (Jobs)
                     {
                         Jobs.Add(job);
                     }
                 }
             }
         }
     }
 }

下面是我的Job类的构造函数:

public Job(PrintSystemJobInfo printJob)
 {
     Name = printJob.Name;
     Status = printJob.JobStatus.ToString();
     Owner = Environment.UserName;
     Priority = printJob.Priority.ToString();
     TimeSubmitted = printJob.TimeJobSubmitted;
     Color = printJob.HostingPrintQueue.CurrentJobSettings.CurrentPrintTicket.OutputColor.Value.ToString();
     DriverName = printJob.HostingPrintQueue.FullName;
     JobId = printJob.JobIdentifier;
// Problem HERE
     string? paperSize = printJob.HostingPrintQueue.CurrentJobSettings.CurrentPrintTicket.PageMediaSize.PageMediaSizeName.ToString();
// End problem
 
     PaperSize = paperSize is null ? "format inconnu" : paperSize;
     double? paperLenght = printJob.HostingPrintQueue.CurrentJobSettings.CurrentPrintTicket.PageMediaSize.Height;
     double? paperWidth = printJob.HostingPrintQueue.CurrentJobSettings.CurrentPrintTicket.PageMediaSize.Width;
     PaperLength = paperLenght is null ? 0 : Math.Round((double)paperLenght * _pixelSize);
     PaperWidth = paperWidth is null ? 0 : Math.Round((double)paperWidth * _pixelSize);
     TotalPages = printJob.NumberOfPages;
 }

能帮我吗?

8dtrkrch

8dtrkrch1#

我希望这个解决方案能与iR-ADVC3525或其他物理打印机一起工作。
Brother MFC-L8690CDW系列打印机,用managementObjectSystem.Management。我用这个构造函数得到正确的信息:

public Job(ManagementObject printJob)
        {
            Name = printJob["Name"].ToString();
            Status = printJob["Status"].ToString();
            Owner = printJob["Owner"].ToString();
            Priority = printJob["Priority"].ToString();
            TimeSubmitted = ManagementDateTimeConverter.ToDateTime(printJob["TimeSubmitted"].ToString());
            Color = printJob["Color"].ToString();
            DriverName = printJob["DriverName"].ToString();
            JobId = int.Parse(printJob["JobId"].ToString());
            PaperSize = printJob["PaperSize"].ToString();
            PaperLength = double.Parse(printJob["PaperLength"].ToString()) / 10;
            PaperWidth = double.Parse(printJob["PaperWidth"].ToString()) / 10;
            TotalPages = int.Parse(printJob["TotalPages"].ToString());
        }

为了得到ManagementObject,我这样做:

public void CatchJobs()
{
    string statusToCheck = "OK"; // Remplacez "Printed" par le statut recherché

    try
    {
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PrintJob");
        ManagementObjectCollection printJobs = searcher.Get();

        foreach (ManagementObject printJob in printJobs)
        {
            string status = printJob["Status"].ToString();
            if (status.Equals(statusToCheck, StringComparison.OrdinalIgnoreCase))
            {
                Job job = new Job(printJob);
                if (!Jobs.Contains(job))
                {
                    lock (Jobs)
                    {
                        Jobs.Add(job);
                    }
                }
            }
        }
    }
    catch (ManagementException e)
    {
        Console.WriteLine("Erreur : " + e.Message);
    }
}

相关问题