0
我正在研究一个应用程序,我必须在原始打印文本之后放置一行额外的文本。PrintQueue.AddJob方法不起作用
为此,我正在使用FindFirstPrinterChangeNotification和FindNextPrinterChangeNotification打印后台处理程序API的方法工作正常。
我能够得到打印队列,显示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();
我的代码成功执行,没有任何例外,但新作业不会与原始文本一起打印。
您刚才复制的MSDN示例代码。其中警告:“此代码仅适用于可检测和打印纯文本的打印机,其中一些打印机不能。”把“一些”变成“最”,而不是大量的点阵式打印机了。不要这样做,请改用PrintDocument。 –
请检查此http://stackoverflow.com/a/6106155/1849024 – imsome1
@HansPassant感谢您的回复。此代码是否适用于POS热敏打印机,或者我也必须使用PrintDocument? –