WPF: How do you print in Landscape mode?
Asked Answered
V

3

12

found this function online, which works great... except I can't figure out how to default it to print in landscape.

private void PrintClick(object sender, RoutedEventArgs e)
{
  PrintDialog dialog = new PrintDialog();
  if (dialog.ShowDialog() == true)
  { dialog.PrintVisual(_PrintCanvas, "My Canvas"); }
}

How does one actually set the default to print my wpf content to landscape mode?

Vitebsk answered 14/3, 2011 at 15:35 Comment(0)
O
16

Edit: Fixed variable name, mentioned by @SHIN JaeGuk

private void PrintClick(object sender, RoutedEventArgs e)
{
    PrintDialog dialog = new PrintDialog();
    if (dialog.ShowDialog() == true)
    { 
        //Set PageOrientation to Landscape
        dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
        dialog.PrintVisual(_PrintCanvas, "My Canvas"); 
    }
}
Overturn answered 26/4, 2012 at 14:35 Comment(0)
F
3

Original Answer This has already been answered: Setting PageOrientation for the Wpf DocumentViewer PrintDialog

End Original Answer

Edit:

It appears there is a problem with the PrintTicket and printing visuals, check out: Same question on MSDN

The original poster on the MSDN forum posted on the last post that the work around they used was to basically capture the visual and convert to xps document for printing, this will allow the usage of PrintTicket to set the orientation of the printed document.

Foetation answered 14/3, 2011 at 15:56 Comment(1)
I'm not looking at printing a Document, but a piece of content. For example, right now I pass in (Visual)mytabs.SelectedContent into my print.printVisual() method. Where exactly would I stick my mytabs.SelectedContent in the answer you pointed to?Vitebsk
E
2
private void PrintClick(object sender, RoutedEventArgs e)
{
   PrintDialog dialog = new PrintDialog();
   if (dialog.ShowDialog() == true)
      { 
         dialog.PrintTicket.PageOrientation=System.Printing.PageOrientation.Landscape;
         dialog.PrintVisual(this, "First LandScape"); 
      }
 }

You need to add a reference to ReachFramework.dll and System.Printing.dll each.

Elmore answered 9/6, 2013 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.