wpf - WPF打印-在WPF PrintDialog上自动设置打印机

标签 wpf printing flowdocument

我试图在不提示用户的情况下将WPF FlowDocument打印到特定打印机。打印机是PDF转换器。

除了可以使用默认打印机进行打印之外,这非常有用:

   PrintDialog pd = new PrintDialog();
   var doc = ((IDocumentPaginatorSource) RTB.Document).DocumentPaginator;
   // I would like to explicitly set the printer to print to here.
   pd.PrintDocument(doc, "Print Document");


在WinForms中,文档上有一个System.Drawing.Printing.PrinterSettings对象,该对象具有PrinterName属性,可以将其设置为所需的打印机,但是在WPF中看不到。

最佳答案

您首先需要在项目中引用System.Printing。然后,可以在声明PrintDialog对象之后立即使用以下代码。

pd.PrintQueue = new PrintQueue(new PrintServer(), "The exact name of my printer");


PrintQueue是代表打印机以及有关该打印队列的所有其他对象的对象。

关于wpf - WPF打印-在WPF PrintDialog上自动设置打印机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15880175/

相关文章:

WPF 如何将右侧的按钮与 x 个按钮对齐

wpf - 如何在 Windows 中制作安装程序 (exe) 文件

c# - 设置升级后如何删除以前的用户设置?

python - python多线程同时打印和输入

c# - 具有 AutoGenerateColumns 的 WPF Datagrid 中的 ItemTemplateSelector

html - 用于打印的 3 个文本 div 的最佳布局

javascript - 如何通过FGL打印机(Boca系统)打印网页

c# - 如何防止在 C# 代码中包装 WPF FlowDocument?

wpf - 如何获取 FlowDocument 中的元素/对象?

c# - 使用 WPF 显示流式富文本