WPF:如何在横向模式下打印?

时间:2011-03-14 15:35:35

标签: wpf printing landscape

在线发现this function,效果很好......除了我无法弄清楚如何默认它以横向打印。

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

如何实际设置默认值以将我的wpf内容打印到横向模式?

3 个答案:

答案 0 :(得分:9)

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"); 
    }
}

答案 1 :(得分:3)

原始答案 这已经回答了: Setting PageOrientation for the Wpf DocumentViewer PrintDialog

结束原始答案

修改

PrintTicket出现问题并打印视觉效果,请查看: Same question on MSDN

MSDN论坛上的原始海报发布在上一篇文章中,他们使用的工作基本上是捕获视觉效果并转换为xps文档进行打印,这将允许使用PrintTicket来设置打印文档的方向

答案 2 :(得分: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"); 
      }
 }

您需要添加对ReachFramework.dll和System.Printing.dll的引用。