I tried this example from MSDN in an ASP.NET MVC project:
public void Print(string printQueueName, string printData)
{
PrintQueue printerQueue = new LocalPrintServer().GetPrintQueue(printQueueName);
// Call AddJob
PrintSystemJobInfo myPrintJob = printerQueue.AddJob();
// Write a Byte buffer to the JobStream and close the stream
Stream myStream = myPrintJob.JobStream;
Byte[] myByteBuffer = UnicodeEncoding.Unicode.GetBytes(printData);
myStream.Write(myByteBuffer, 0, myByteBuffer.Length);
myStream.Close();
}
I tried to print to PDF, XPS and OneNote virtual printers. After confirming printing dialog, printing job appears in printer queue then disappears, and the printed file is created, but with 0 byte size!!!
I don't know where is my fault, and hope to find help here.
Thanks in advance.