How to Export the Report Programmatically without Showing Report Viewer

Let's assume we need to export the report to PDF but don't need to show the Report Viewer.

First, you may call ReportViewer 's Export method, it requires you to have ReportViewer with loaded document (but the Viewer could be invisible):

reportViewer.Export(PerpetuumSoft.Reporting.WPF.Model.ExportFormat.Pdf, false);

Simple scenario is to create ReportViewer, set its ReportSource, subscribe to the DocumentLoaded event, add export code in its handler and call ReportViewer's RenderDocument method.

Another way is to use export filter's abilities:

ReportSource reportSource = new ReportSource();
reportSource.Source = @"doc1.rst";
reportSource.Parameters.Add("Property1""some text");
reportSource.Parameters.Add("Property2", 123);
reportSource.DataSources.Add("DataSource"new List<string>(){ "One""Two""Three" });
// Now we need to render document
reportSource.RenderDocument();
// now we can export it to pdf
var filter = new PerpetuumSoft.Reporting.Export.Pdf.PdfExportFilter();
filter.Export(reportSource.Document, "out.pdf"false);

Its important to pass false as the last parameter of Export method, if you will pass true, the Windows Form dialog will be shown. So, second way is simpler than the first one, but it do not allow you to show WPF-based PDF options dialog.

Add Feedback