Nor*_*ggs 5 .net c# windows printing
我试图在没有任何对话框的情况下使用本地打印机打印 xps 文件。当我调用 PrintQueue.AddJob() 执行停止时,它不会转到下一行代码,但不会引发任何异常并且程序继续运行。
我使用的代码:
LocalPrintServer lps = new LocalPrintServer();
PrintQueue pq = lps.GetPrintQueue("printQueueName");
pq.AddJob("jobName", pathToFile, false);
Run Code Online (Sandbox Code Playgroud)
谢谢你。
我注意到同样的问题,但我只找到了一些解决方法。我尝试使用该方法解决该问题CreateXpsDocumentWriter.Write,但这从我的文档中删除了一些页面设置(例如每页的页面方向)。
确实发现使用PrintQueueStream有效并保留页面设置。
https://learn.microsoft.com/en-us/dotnet/api/system.printing.printqueuestream
LocalPrintServer lps = new LocalPrintServer();
PrintQueue pq = lps.GetPrintQueue("printQueueName");
using (var fileStream = new StreamReader(pathToFile))
using (var printStream = new PrintQueueStream(pq, "jobName", true))
{
fileStream.BaseStream.CopyTo(printStream);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
710 次 |
| 最近记录: |