我试图在不提示用户的情况下将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/