我试图在共享打印机上打印文档;我需要获取打印队列详细信息。以下代码始终从“Microsoft XPS Document”获取队列作为作业数= 0.但我的默认打印机配置为“HP LaserJet P1505n”
LocalPrintServer server = new LocalPrintServer()
PrintQueueCollection queueCollection = server.GetPrintQueues();
PrintQueue printQueue = null;
foreach (PrintQueue pq in queueCollection)
{
Logger.LogInfo("PrintQueue1", "Printer1 Queue Name " + pq.FullName);
printQueue = pq;
numberOfJobs = printQueue.NumberOfJobs;
Logger.LogInfo("numberOfJobs1"+ numberOfJobs);
}
如何从特定的共享打印机获取打印队列详细信息?我也试过跟着
PrintServer server = new PrintServer(@"\\192.168.100.168\HP LaserJet P1505n");
但得到错误:
Win32错误:文件名,目录名或卷标语法是 不正确
我在这里缺少什么?
答案 0 :(得分:4)
如何从特定的共享打印机获取打印队列详细信息?
尝试这样的事情:
// string.Empty or null for local printers
string printServerName = @"\\server";
string printQueueName= "printer";
PrintServer ps = string.IsNullOrEmpty(printServerName)
// for local printers
? new PrintServer()
// for shared printers
: new PrintServer(printServerName);
PrintQueue pq = ps.GetPrintQueue(printQueueName);
Console.WriteLine(pq.FullName);
Console.WriteLine(pq.NumberOfJobs);
// output is printer uri (\\server\printer) and 0.
也可以使用服务器IP地址(如字符串)代替服务器名称。
string printServerName = @"\\192.168.1.111"; // for example
即
对于本地打印机PDFCreator设置
string printServerName = null;
string printerName = "PDFCreator";
和服务器S上的共享打印机P
string printServerName = @"\\S";
string printerName = "P";
答案 1 :(得分:0)
System.Printing.PrintServer类文档
尝试一下:
var myServer = @"\\192.168.100.168";
使用以下代码:
// Create a PrintServer
// "theServer" must be a print server to which the user has full print access.
// var myServer = @"\\theServer"
PrintServer myPrintServer = new PrintServer(myServer);
// List the print server's queues
PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
String printQueueNames = "My Print Queues:\n\n";
foreach (PrintQueue pq in myPrintQueues)
{
printQueueNames += "\t" + pq.Name + "\n";
}
Console.WriteLine(printQueueNames);
Console.WriteLine("\nPress Return to continue.");
Console.ReadLine();