1

我使用以下代码打印 pdf :

var fileName = filepath;
ProcessStartInfo psInfo = new ProcessStartInfo();
psInfo.Arguments = ConfigurationManager.AppSettings["printer_name"];
psInfo.FileName = fileName;
psInfo.WindowStyle = ProcessWindowStyle.Hidden;
psInfo.Verb = "print";
psInfo.CreateNoWindow = false;
psInfo.UseShellExecute = true;
process = Process.Start(psInfo);

以下以获取打印机的状态:

string query = string.Format("SELECT * from Win32_Printer "+ "WHERE Name LIKE '%   {0}'",printerName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection coll = searcher.Get();

foreach (ManagementObject printer in coll)
{
    foreach (PropertyData property in printer.Properties)
    {
        Logger.LogInfo(""+property.Name, "" +property.Value);
    }
}

并尝试以下监控打印队列:

LocalPrintServer server = new LocalPrintServer();
PrintQueueCollection queueCollection =      server.GetPrintQueues();
PrintQueue printQueue = null;
foreach (PrintQueue pq in queueCollection)
{
    if (pq.FullName == "HP LaserJet P1505n")
        printQueue = pq;
}

int numberOfJobs = 0;
if (printQueue != null)
    numberOfJobs = printQueue.NumberOfJobs;

我只想知道我使用(1)打印的文档是否成功打印!(2)nd 代码片段总是显示相同的属性 anme 和值。因此无法通知打印状态。(3)rd 代码片段总是监视队列一次并显示“0”作业数。

那么取回打印状态的实际方法是什么?

4

1 回答 1

0

了解打印作业状态..!尝试这个,

 SelectQuery qry = new SelectQuery("PrintJob");

  using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(qry))
  using (ManagementObjectCollection printJobs = searcher.Get())
     foreach (ManagementObject printJob in printJobs)
       {
    string name = (string) product["Name"];
    string[] nameParts = name.Split(',');
    string printerName = nameParts[0];
    string jobNumber = nameParts[1];
    string document = (string) product["Document"];
    string jobStatus = (string) product["JobStatus"];
       }

我希望这有帮助。

于 2013-11-28T09:26:03.683 回答