Reputation: 12215
I want to save an IDocumentPaginatorSource
, e.g. FixedDocument
or XpsDocument
, as a PDF by using the virtual printer "Microsoft Print to 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
.
I checked all classes in the System.Printing
namespace but did not find any way to set these two settings. Maybe it's possible to retrofit these seetings into the PrintTicket
by extending the print schema? If so, how exactly would you do that?
Upvotes: 4
Views: 3252