使用C#最佳方法打印文档 [英] Printing a document in C# best approach
问题描述
我在C#中搜索一个命名空间,通过它可以打印和监控打印。目前我使用'process'来打印pdf;但在这里我无法监控打印。因为进程只是将文件抛出到打印机。我经历了Win32_Printer和System.printing它们都在处理控制/监视打印作业但不打印文档。
我现在如何打印:
ProcessStartInfo psInfo = 新 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);
WMI的作用:一种使用WMI控制打印作业的简单方法和 http://msdn.microsoft.com/en-us/library/aa394370.aspx
我需要做的就是检查我此刻打印的文件的打印状态。是否打印!!
获取的列表 打印队列在本地计算机上,尝试PrintServer ' s GetPrintQueues方法。
一旦有了与相关打印机关联的PrintQueue对象的实例,就可以使用它来访问打印机的状态(IsOffline,IsPaperOut等)。此外,您可以使用它 获取的列表在给定队列中的作业(GetPrintJobInfoCollection)然后将允许 to 获取特定于作业的状态信息(IsInError,IsCompleted,IsBlocked等)。
http://support.microsoft.com/kb/322091 [ ^ ]
foreach (ManagementObject printJob in printJobs)
{
// Win32_PrintJob.Name属性的格式为PrinterName,JobNumber
string name = ( string )product [ Name];
string [] nameParts = name.Split(' 跨度>);
string printerName = nameParts [ 0 ];
string jobNumber = nameParts [ 1 ];
string document =( string )product [ 文件];
string jobStatus =( string )product [ JobStatus];
// 处理工作属性......
}
am searching for a namespace in C# through which i can "print and monitor printing".Currently i used 'process' to print a pdf ; But here i cannot monitor printing.Since process just throws document to printer.I went through Win32_Printer and System.printing both of them are dealing with "controlling/monitoring print jobs" but not printing a document.
How i print now:
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);
what WMI does: A simple approach for controlling print jobs using WMI and http://msdn.microsoft.com/en-us/library/aa394370.aspx
All i need to do is check print status of a document i have printed at the moment.Printed or not!!
To get a list of print queues on the local machine, try PrintServer's GetPrintQueues method. Once you have an instance of the PrintQueue object associated with the relevant printer, you can use it to access the printer's status (IsOffline, IsPaperOut, etc.). Also, you can use it to get a list of the jobs in the given queue (GetPrintJobInfoCollection) which then will allow you to get job-specific status information (IsInError, IsCompleted, IsBlocked, etc.).
http://support.microsoft.com/kb/322091[^]
foreach (ManagementObject printJob in printJobs) { // The format of the Win32_PrintJob.Name property is "PrinterName,JobNumber" 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"]; // Process job properties... }
这篇关于使用C#最佳方法打印文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!