How can I generate PDF from Printdocument?

finalbyte picture finalbyte · Nov 27, 2014 · Viewed 7.7k times · Source

[Language: C#] I have wrote some code to printdocument and I get a preview with microsoft's controls built-in (System.Windows.Forms.PrintPreviewControl, System.Drawing.Printing.PrintDocument).

How can I convert in PDF the file that I print with this code:

String filename="c:\\file.prt";
PrintDialog dlg = new PrintDialog();
dlg.Document = this;
dlg.AllowSelection = this.ListView.SelectedIndices.Count > 0;
dlg.AllowSomePages = true;
dlg.PrinterSettings.PrintToFile = true;
dlg.PrinterSettings.PrintFileName = filename;

I don't want print by virtual pdf printer software, because there is a "Save as" dialog... Can I convert in PDF by Ghostscript, but this one want a Postscript file, don't work with "PrintFileName" format type.

How can i convert printfile to postscript PS, or in pdf?

Thanks.

Answer

finalbyte picture finalbyte · Nov 27, 2014

I have resolved with this: http://www.nathanpjones.com/wp/2013/03/output-to-pdf-in-wpf-for-free/

The format is XPS....

Thanks.