Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: How do you print in Landscape mode?

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?

like image 441
michael Avatar asked Mar 14 '11 15:03

michael


People also ask

Can printer print landscape?

Printers can print in portrait or landscape mode. In portrait mode, which is the default, the printer prints pages that are 8.5″ wide and 11″ tall. In landscape mode, the page is turned on its side. This mode may be useful if you are trying to print a spreadsheet or sign that is wider than it is long.

What is Landscape in print option?

1. When referring to graphics or printing, landscape mode is a horizontal orientation of a document or image. Landscape mode is commonly used to print charts, wider images, and text that may not fit properly if the page is oriented in portrait mode (vertically).


2 Answers

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"); 
    }
}
like image 55
Badiboy Avatar answered Oct 03 '22 01:10

Badiboy


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.

like image 35
Ashu Avatar answered Oct 03 '22 01:10

Ashu