Saving report to disk in PDF

0

I took a legacy code here and I have no WindowsForms experience.

The case is, a report is generated and saved inside an object of type PrintDocument.

Then it seems to populate another object, of type PrintPriviewDialog, and already calls the print dialog that the report appears on the screen.

What I need is just to not call anything and save the PDF to the PrintDocument disk, how?

    
asked by anonymous 18.05.2016 / 15:44

2 answers

0

It calls the dialog because it needs to choose the form (software) to convert to PDF. To do it directly you have to access a library that does the writing for PDF and you will usually have to pay for one.

You can find a post explaining a possible here . I have not tested it but it seems to be exactly what you are looking for.

    
18.05.2016 / 16:17
0

I decided with some parameters that were missing in several tutorials that I found and other answers here in StackO, I do not know why exactly the two of them worked and in mine, maybe it's something relative to versions.

It turned out that I did not check if it was really necessary to convert the PrintDialog Object to PrintDocument, but that's how I did it:

this.printDocumentFunciona = this.printDialog1.Document;

The implementation itself:

this.printDocumentFunciona.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
this.printDocumentFunciona.DefaultPageSettings.PrinterSettings.PrintToFile = true;
this.printDocumentFunciona.DefaultPageSettings.PrinterSettings.PrintFileName = "NomeArquivo.xps";

this.printDocumentFunciona.PrintController = new StandardPrintController();
this.printDocumentFunciona.Print();

Important, if you select the Foxit Printer, it does not work at all, the dialog for choosing the name always appears, but using the Windows XPS printer or Office / Windows PDF, it works without opening anything.

    
02.06.2016 / 18:17