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

Bro*_*ing 9 printing wpf 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");
Run Code Online (Sandbox Code Playgroud)

在WinForms中,文档上有一个System.Drawing.Printing.PrinterSettings对象,它有一个PrinterName属性,可以设置为我想要的打印机,但我在WPF中没有看到.

Ste*_*bob 18

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

pd.PrintQueue = new PrintQueue(new PrintServer(), "The exact name of my printer");
Run Code Online (Sandbox Code Playgroud)

PrintQueue对象表示打印机以及有关该打印队列的所有其他内容.

  • 嗨我得到了这个工作printDlg.PrintQueue = new PrintQueue(new PrintServer(@"\\ servername"),"printername"); 你的例子让我想到了这一点. (2认同)