我正在开发一个应用程序,我必须在原始打印文本后添加一行额外的文本。
为此,我使用 Print Spooler API 的 FindFirstPrinterChangeNotification 和 FindNextPrinterChangeNotification 方法,效果很好。
我能够获取打印队列,其中显示作业数 1。
我正在使用以下代码在打印队列中添加新作业:
// Create the printer server and print queue objects
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();
// Call AddJob
PrintSystemJobInfo myPrintJob = defaultPrintQueue.AddJob();
// Write a Byte buffer to the JobStream and close the stream
Stream myStream = myPrintJob.JobStream;
Byte[] myByteBuffer = UnicodeEncoding.Unicode.GetBytes("This is a test string for the print job stream.");
myStream.Write(myByteBuffer, 0, myByteBuffer.Length);
myStream.Close();
我的代码成功执行,没有任何异常,但新作业没有与原始文本一起打印。
最佳答案
正如 Tony 在评论中指出的那样,JobStream 在 Windows 8 及更高版本的 .NET Framework 4.5 中已更改为使用 XPS 文档格式。如果您想打印,则必须遵循指南。
我还没有找到有效的解决方案,但您可以尝试使用 XPS Printing API
关于c# - PrintQueue.AddJob 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42241600/