我正在开发一个应用程序,我必须在原始打印文本之后添加一行额外的文本。
为此,我使用了 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();
我的代码毫无例外地成功执行,但新作业没有与原始文本一起打印。