【问题标题】:How to print a wpf window without showing it on the screen?如何打印 wpf 窗口而不在屏幕上显示它?
【发布时间】:2012-01-17 12:40:19
【问题描述】:

我有一个要求,我需要打印一份完整的表格,而不是在屏幕上显示。

我需要的是:

  1. 初始化表单
  2. 打印出来

全部不显示在屏幕上。

有什么建议吗?

【问题讨论】:

  • 嗨。说吧,这和mvvm有什么关系?

标签: wpf printing


【解决方案1】:

您可以使用 PrintDialog.PrintVisual 方法执行此操作。

var capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

//get scale of the print wrt to screen of WPF visual
var scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight / this.ActualHeight);

//Transform the Visual to scale
this.LayoutTransform = new ScaleTransform(scale, scale);

// Get the size of the printer page
var sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

//update the layout of the visual to the printer page size.
this.Measure(sz);
this.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

//now print the visual to printer to fit on the one page.
printDlg.PrintVisual(visual, String.Empty);

【讨论】:

  • 我看到这有两票,但它真的回答了这个问题吗?看起来视觉(这个)仍然必须在屏幕上显示才能打印。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-26
  • 1970-01-01
相关资源
最近更新 更多