C# 文档是否用C打印#

C# 文档是否用C打印#,c#,.net,printing,process,system.management,C#,.net,Printing,Process,System.management,我使用以下代码打印pdf: var fileName = filepath; ProcessStartInfo psInfo = new ProcessStartInfo(); psInfo.Arguments = ConfigurationManager.AppSettings["printer_name"]; psInfo.FileName = fileName; psInfo.WindowStyle = ProcessWindowStyle.Hidden; psInfo.Verb = "p

我使用以下代码打印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”numberofjobs


那么,返回打印状态的实际方法是什么呢?

了解打印作业状态。。!试试这个

 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"];
       }
我希望这有帮助