Search code examples
printingxpsxpsdocumentxpsviewer

Default Layout Orientation when printing XPSs using the WPF XPS Viewer


Is there a way to set the Default Layout Orientation when printing XPSs using the WPF XPS Viewer?

My fixed document XPS has its page orientation set to Landscape, the Page Media Size has a width that is longer that its height and it displays correctly in the Viewer as Landscape. Its just that when you hit the print button the Print Dialog preferences are defaulted to Portrait and it prints as such.

I'd rather not have to alter the users default print settings I'd much prefer it if the XPS Viewer would print the XPS as it was designed to be printed.


Solution

  • Fill the field of the PrintTicket:

      PrintDialog pd = new PrintDialog();
      PrintTicket pt = new PrintTicket();
      pt.PageOrientation = PageOrientation.Landscape;
      pd.PrintTicket = pd.PrintQueue.MergeAndValidatePrintTicket(pd.PrintQueue.DefaultPrintTicket, pt).ValidatedPrintTicket;
      if (pd.ShowDialog() == true)
      {
        ...
      }