简体   繁体   English

如何在WPF C#中为FlowDocument选择打印机

[英]How to select printer for FlowDocument in wpf c#

I am trying to print a FlowDocument directly to a pdf using Microsoft Print to pdf. 我正在尝试使用Microsoft Print to pdf将FlowDocument直接打印为pdf。 Each time I want to print it sets the printer to the last printer that was used, I need it to set to "Microsoft Print to PDF". 每次我要打印时,都将打印机设置为使用的最后一台打印机,我需要将其设置为“ Microsoft Print to PDF”。

// Create a PrintDialog 
PrintDialog printDlg = new PrintDialog();
// Create a FlowDocument dynamically. 
FlowDocument doc = CreateFlowDocument();
doc.Name = "OrderReceipt"+orderNo;
// Create IDocumentPaginatorSource from FlowDocument 
IDocumentPaginatorSource idpSource = doc;
// Call PrintDocument method to send document to printer 
printDlg.PrintDocument(idpSource.DocumentPaginator, "Save PDF");

Is this possible? 这可能吗?

您可能正在使用默认打印机设置,可以将其设置为最后使用的打印机: https : //support.microsoft.com/zh-cn/help/4028622/windows-10-how-to-set-a-default -打印机

Have you tried calling PrintDialog.ShowDialog()? 您是否尝试过调用PrintDialog.ShowDialog()? It pops up the printer options and lets you select which printer to send to and set preferences. 它弹出打印机选项,让您选择要发送到的打印机并设置首选项。

// Create IDocumentPaginatorSource from FlowDocument 
IDocumentPaginatorSource idpSource = doc;
// Display printer options
if( printDlg.ShowDialog() ?? false )
{
   // Call PrintDocument method to send document to printer 
   printDlg.PrintDocument(idpSource.DocumentPaginator, "Save PDF");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM