简体   繁体   English

使用 System.Print 在“Microsoft Print to PDF”打印机中设置文件名

[英]Set file name in "Microsoft Print to PDF" printer using System.Print

I want to save an IDocumentPaginatorSource , eg FixedDocument or XpsDocument , as a PDF by using the virtual printer "Microsoft Print to PDF":我想通过使用虚拟打印机“Microsoft Print to PDF”将IDocumentPaginatorSource ,例如FixedDocumentXpsDocument保存为PDF:

var printServer = new System.Printing.PrintServer();
var queue = printServer.GetPrintQueue("Microsoft Print to PDF");
var writer = System.Printing.PrintQueue.CreateXpsDocumentWriter(queue);
writer.Write(Document.DocumentPaginator); // Document = IDocumentPaginatorSource

This works, but makes the printer open a file save dialog.这有效,但会使打印机打开文件保存对话框。 I would like to set the file name programmatically and either suppress this dialog completely or at least set the initial file name in the dialog.我想以编程方式设置文件名,要么完全取消此对话框,要么至少在对话框中设置初始文件名。 Is this possible?这可能吗?

I know, that this can be done when using System.Drawing.Printing.PrintDocument by setting PrinterSettings.PrintFileName and PrinterSettings.PrintToFile (see 1 , 2 ), but this is the old printing framework that does not support IDocumentPaginatorSource .我知道,这可以在使用System.Drawing.Printing.PrintDocument通过设置PrinterSettings.PrintFileNamePrinterSettings.PrintToFile (参见12 )来完成,但这是不支持IDocumentPaginatorSource的旧打印框架。

I checked all classes in the System.Printing namespace but did not find any way to set these two settings.我检查了System.Printing命名空间中的所有类,但没有找到任何方法来设置这两个设置。 Maybe it's possible to retrofit these seetings into the PrintTicket by extending the print schema ?也许可以通过扩展打印模式将这些设置改造到PrintTicket If so, how exactly would you do that?如果是这样,你会怎么做?

I don't have a solution using the "Microsoft Print to PDF printer", but if you switched to using the Win2PDF printer driver you can set the file name programatically through the registry.我没有使用“Microsoft Print to PDF 打印机”的解决方案,但是如果您切换到使用Win2PDF打印机驱动程序,您可以通过注册表以编程方式设置文件名。 To do this, see the documentation for the "PDFFileName" or "PDFDefaultFileName" registry settings.为此,请参阅“PDFFileName”或“PDFDefaultFileName”注册表设置的文档。

暂无
暂无

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

相关问题 如何使用Windows 10附带的“Microsoft Print To PDF”打印机以编程方式在WPF中打印到PDF文件? - How to programmatically print to PDF file in WPF using the “Microsoft Print To PDF” printer that comes with Windows 10? 使用Microsoft Print to PDF打印机打印为PDF - Print to PDF with Microsoft Print to PDF printer 在Winforms中使用自定义打印机打印PDF文件 - Print PDF File using Custom Printer in Winforms 以编程方式将 Microsoft Print 中的文件名和路径设置为 PDF 打印机 - Programmatically set filename and path in Microsoft Print to PDF printer 如何使用 Windows 10 附带的 Microsoft Print To PDF 打印机以编程方式打印到 PDF 文件而不提示在 C# 中输入文件名 - How to programmatically print to PDF file without prompting for filename in C# using the Microsoft Print To PDF printer that comes with Windows 10 以编程方式提供文件路径作为“Microsoft Print to PDF”打印机的输入文件 - Programmatically provide a filepath as input file for “Microsoft Print to PDF” printer C#- 使用 Microsoft 打印机打印现有 PDF - C#- Print Exisitng PDF using Microsoft Printer 用于 WebBrowser 控制的“Microsoft Print to PDF”打印机 - “Microsoft Print to PDF” printer for webBrowser control 打印到.pdf打印机会创建损坏的文件 - Print to .pdf printer creates corrupted file 在文件名中使用逗号(,)时,Microsoft Print to PDF无法正常工作 - Microsoft Print to PDF not working when used comma(,) in file name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM