C# XPS PrintSystemJobInfo printing set margin and orientation depending on pages?

45 views Asked by At

I am using this code to print XPS files which works fine.
Microsoft: How to: Programmatically Print XPS Files

The problem is that some XPS document have both portrait and landscape pages.
If I print the document from an XPS viewer, then it works fine.
But when I use this code then it only prints portrait mode and also the margins are not correct. (pushed right)

I tried to use:

    var queue = localPrintServer.GetPrintQueue("printer name");
    PrintTicket pt = queue.DefaultPrintTicket;
    pt.PageOrientation = PageOrientation.Landscape;
    PrintSystemJobInfo xpsPrintJob = queue.AddJob(f.Name, nextFile, false, pt);

This works but now all pages printed in landscape.

Is there any way to get the orientation from the XPS document page and print with that orientation, and also set all margins maybe to 0?

What would be the best approach?

I am quite new with printing stuff so not an expert in this area.

0

There are 0 answers