WPF: How do you print in Landscape mode?

試著忘記壹切 提交于 2019-12-01 02:57:05

问题


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?


回答1:


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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/5300802/wpf-how-do-you-print-in-landscape-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!