PrintQueue.AddJob () stops execution

I am trying to print an xps file with a local printer without any dialogue. When I call PrintQueue.AddJob (), execution stops, it does not go to the next line of code, but it does not raise any exceptions, and programming continues to work.

The code I'm using is:

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

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

Thank.

+4
source share
1 answer

I noticed the same problem, but I managed to find workarounds. I tried to work around the problem using the method CreateXpsDocumentWriter.Write, but removed some page settings from my document (for example, "Page Orientation to Page").

, PrintQueueStream . https://docs.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);
}
0

Source: https://habr.com/ru/post/1680113/


All Articles