我使用以下代码打印 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”作业数。
那么取回打印状态的实际方法是什么?