I am trying to print a FlowDocument directly to a pdf using Microsoft Print to 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".
// 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()? 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");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.