NorthEggs
NorthEggs

Reputation: 51

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.

Upvotes: 5

Views: 1079

Answers (1)

Denxorz
Denxorz

Reputation: 346

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);
}

Upvotes: 3

Related Questions