Reputation: 205
I am working on an application where I have to put an extra line of text after original printed text.
For this, I am using FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification methods of Print Spooler API which works fine.
I am able to get Print Queue which shows number of job count 1.
I am using following code to add a new job in Print Queue:
// 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();
My code execute successfully without any exception but the new job doesn't get printed along with original text.
Upvotes: 2
Views: 3564
Reputation: 2161
As Tony pointed out in the comments, the JobStream has changed in .NET Framework 4.5 for Windows 8 and up to use the XPS document format. If you want to print, you're going to have to follow the guideline.
I have not found a solution that works, but you can try using the XPS Printing API
The closest solution to that I found were here and here as mentioned by Microsoft here
Upvotes: 2