我正在开发一个应用程序,在这个应用程序中,我必须在原始打印文本之后添加一行额外的文本。
为此,我使用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();我的代码成功执行,没有任何异常,但新作业不会与原始文本一起打印。
发布于 2017-10-25 10:49:01
正如托尼在评论中指出的那样,在Windows8和更高版本的.NET Framework4.5中,JobStream已经更改为使用XPS格式。如果你想打印,你必须遵循指导原则。
我还没有找到有效的解决方案,但您可以尝试使用XPS Printing API
https://stackoverflow.com/questions/42241600
复制相似问题