wpf - 如何打印wpf窗口而不将其显示在屏幕上?

标签 wpf printing

我有一个要求,我需要打印完整的表单而不将其显示在屏幕上。

我需要的是:

  1. 初始化表单
  2. 打印

全部不显示在屏幕上。

请问有什么建议吗?

最佳答案

您可以使用 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);

关于wpf - 如何打印wpf窗口而不将其显示在屏幕上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8894770/

相关文章:

c# - WPF字体大小不变

c# - 寻找在 Docx -> Pdf 转换服务中使用的 Pdf 打印机

python - YML文件打印错误的次数

windows - 如何使用命令行将所有 .pdf 文件名打印到输出文件?

android - 使用 Android eclipse ADT 打印

.net - 我需要 WPF 4 的 Accordion 控件

c# - 以编程方式 WPF listbox.ItemsSource 更新

c# - WPF代码分析: CA2202 Do not dispose objects multiple timesObject

WPF 数据网格 : Loading_Completed Event?

html - 打印时未应用文本背景