簡體   English   中英

如何確定打印機作業的特定打印機屬性?

[英]How to determine specific printer properties for a printer job?

我正在研究一些代碼,這些代碼監視打印機隊列,然后使用事件信息收集有關作業的一些細節,包括#頁,方向,是否為彩色以及請求了多少份副本。

我使用Merrion Computing(現在是開源的)中的代碼捕獲事件。 處理互操作。

對於Color,應該將其存儲在JOB_INFO_2.pDeviceMode.dmColor;中。 但是,無論我如何提交作業(使用從多個應用程序(包括word和adobe)中使用打印機屬性進行打印的彩色或黑白),它始終表示顏色。 我直接調試了該代碼,並且互操作看起來是正確的,因此我使用事件中的JobId通過.NET通過代碼查詢打印系統(如下); 並且它包含與復印件和顏色完全相同的設置。

int iJobId = e.PrintJob.JobId;

LocalPrintServer printServer = new LocalPrintServer();
PrintQueueCollection queueCollection = printServer.GetPrintQueues();
foreach (PrintQueue queue in queueCollection)
{
queue.Refresh();
if(queue.FullName.Equals(e.PrintJob.PrinterName,StringComparison.OrdinalIgnoreCase))
{
  int? iPageCount;

  PrintJobInfoCollection jobs = queue.GetPrintJobInfoCollection();
  foreach(PrintSystemJobInfo job in jobs)
  {
    job.Refresh();
    if(job.JobIdentifier==iJobId)
    {
      iPageCount = job.NumberOfPages;
    }
  }

  //-- Found the Printer...
  int? iCopyCount=queue.CurrentJobSettings.CurrentPrintTicket.CopyCount;
  PageOrientation? eOrientation = queue.CurrentJobSettings.CurrentPrintTicket.PageOrientation;
  OutputColor? eColor = queue.CurrentJobSettings.CurrentPrintTicket.OutputColor;

  Debug.WriteLine("queue=" + queue.FullName + ", Copies=" + iCopyCount.Value + ",Color=" + eColor.ToString() + ", pagecount=" + "unk" /*iPageCount.Value*/ + ", Orientation=", eOrientation.ToString());
  Debug.WriteLine("---");
}
}

有沒有人看到一種可靠的方法來檢索特定打印機作業的份數和頁數(最好使用.NET)? 一世

我確實發現這篇文章描述了相同類型的問題,但那里沒有解決方案。

使用C#確定當前的打印作業顏色

還應注意,以上文章中的WMI代碼也返回顏色。

我進入了啟用的事件日志以進行打印( http://www.papercut.com/kb/Main/LogPrintJobsInEventViewer )。 查看打印事件的詳細信息; 顏色設置為預期的“ 2”,表示灰度。

很明顯,Windows子系統正在接收所請求的設置。 但是,我無法使用WMI,System.Printing的命名空間或Merrion的打印監控庫中的互操作檢索值,在這些值中所有值均指示該作業是彩色的,具有正確的頁面和副本數。

是否可以獲取為此打印生成的假脫機文件,以檢查它是否正在設置dmColor設置?

您從事件日志2中獲得的設置對應於DMCOLOR_COLOR而不是DMCOLOR_MONOCHROME,因此日志中的顏色設置似乎也認為它也是顏色。

可能是打印機驅動程序在創建作業時將其提交為彩色時有點偷偷摸摸,然后在后台處理程序中發送“設置設備設置”消息將其更改為單色? 如果是這樣,則在假脫機文件中應該有一個SPT_DEVMODE記錄。

檢查本文以獲取假脫機文件讀取器: http : //www.codeproject.com/Articles/10586/EMF-Printer-Spool-File-Viewer

您需要刷新慢跑,直到標志IsSpooling變為false。

for (int i = 0; i < jobs.Count(); i++)
{
    try
    {
        int timeOut = 20000;
        var jobInfo = jobs.ElementAt(i);                               
        while (jobInfo.IsSpooling && timeOut > 0)
        {
            Thread.Sleep(100);
            timeOut-=100;
            jobInfo.Refresh(); 
        }                                                                                                                                       var pages = Math.Max(jobInfo.NumberOfPages,jobInfo.NumberOfPagesPrinted);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM