Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrintQueue.AddJob() stops execution

I am trying to print an xps file with a local printer without any dialog. When I call PrintQueue.AddJob() the execution stops it doesn't go to the next line of code but it doesn't throw any exception and the programming keeps running.

The code I use:

LocalPrintServer lps = new LocalPrintServer();
PrintQueue pq = lps.GetPrintQueue("printQueueName");

pq.AddJob("jobName", pathToFile, false);

Thank you.

like image 960
NorthEggs Avatar asked Oct 17 '22 10:10

NorthEggs


1 Answers

I noticed the same issue, but I only managed to find some workarounds. I tried to work around the issue by using the CreateXpsDocumentWriter.Write method, but that removed some page settings from my document (like Page Orientation per page).

Did find out that using PrintQueueStream works and keeps the page settings. https://learn.microsoft.com/en-us/dotnet/api/system.printing.printqueuestream

LocalPrintServer lps = new LocalPrintServer();
PrintQueue pq = lps.GetPrintQueue("printQueueName");

using (var fileStream = new StreamReader(pathToFile))
using (var printStream = new PrintQueueStream(pq, "jobName", true))
{
    fileStream.BaseStream.CopyTo(printStream);
}
like image 166
Denxorz Avatar answered Oct 21 '22 00:10

Denxorz