[英]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
,例如FixedDocument
或XpsDocument
保存为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.PrintFileName
和PrinterSettings.PrintToFile
(参见1 、 2 )来完成,但这是不支持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.