【问题标题】:Set file name in "Microsoft Print to PDF" printer using System.Print使用 System.Print 在“Microsoft Print to PDF”打印机中设置文件名
【发布时间】:2019-10-10 23:03:45
【问题描述】:

我想保存一个IDocumentPaginatorSource,例如FixedDocumentXpsDocument,使用虚拟打印机“Microsoft Print to PDF”作为 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

这可行,但会使打印机打开一个文件保存对话框。我想以编程方式设置文件名,或者完全禁止该对话框,或者至少在对话框中设置初始文件名。这可能吗?

我知道,这可以在使用System.Drawing.Printing.PrintDocument 时通过设置PrinterSettings.PrintFileNamePrinterSettings.PrintToFile 来完成(参见12),但这是不支持IDocumentPaginatorSource 的旧打印框架.

我检查了System.Printing 命名空间中的所有类,但没有找到任何方法来设置这两个设置。也许有可能通过extending the print schema 将这些设置改造成PrintTicket?如果是这样,你会怎么做?

【问题讨论】:

标签: c# pdf printing xpsdocument fixeddocument


【解决方案1】:

我没有使用“Microsoft Print to PDF 打印机”的解决方案,但如果您切换到使用Win2PDF 打印机驱动程序,您可以通过注册表以编程方式设置文件名。为此,请参阅"PDFFileName" or "PDFDefaultFileName" 注册表设置的文档。

【讨论】:

  • 这不是我的解决方案。我不想依赖某些第 3 方软件,尤其是在它不是免费的时候。
猜你喜欢
  • 1970-01-01
  • 2017-08-16
  • 1970-01-01
  • 2021-06-06
  • 1970-01-01
  • 2016-03-03
  • 2017-07-04
  • 2015-11-01
相关资源
最近更新 更多