Saving report on disk in PDF

Asked

Viewed 142 times

0

I took a legacy code here and I have no experience with Windowsforms.

The case is, a report is generated and saved within a Printdocument type object.

Then it seems that it populates another object, type Printpriviewdialog, and already calls the print dialog that appears the report on the screen.

What I need is just to call nothing and save the PDF to the Printdocument disc, like?

  • You can [Edit] the question and add the code?

2 answers

0

I solved with some parameters that were missing in several tutorials I found and other answers here in Stacko, I do not know why exactly in the guys worked and in my no, maybe it is something relative with versions.

It turned out that I didn’t 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();

Importantly, if you select the Foxit Printer, it doesn’t work at all, the dialog always appears to choose the name, but using the Windows XPS printer or the Office/Windows PDF printer, it works without opening anything.

0

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

You can find a post that explains a possible solution here. I haven’t tested but it seems to be exactly what you’re looking for.

  • So it turned out that I used the standard windows printer even in XPS and it was a good one, it took me to notice some parameters that had to be set and I didn’t know, I’ll put the solution here below, but vlw by link!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.