Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a PDF from an embedded report definition without server or UI?

Is it possible for a stand alone executable to generate a report and output it as PDF (or one of the other export options available from the report viewer) without displaying the ReportViewer control?

The report definition should be embedded in the executable and should not use the Reporting Services web service.

like image 558
Magnus Lindhe Avatar asked Sep 26 '08 07:09

Magnus Lindhe


2 Answers

Actually you don't need a ReportViewer at all, you can directly instantiate and use a LocalReport:

LocalReport report = new LocalReport();
report.ReportPath = "templatepath";
// or use file from resource with report.ReportEmbeddedResource

// add parameters, datasource, etc.

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;

byte[] bytes;
bytes =report.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

// save byte[] to file with FileStream or something else
like image 124
csgero Avatar answered Oct 27 '22 00:10

csgero


You don't have to show the control itself.

ReportViewer rv = new ReportViewer();
rv.LocalReport.ReportPath = "templatepath";
// or use file from resource with rv.LocalReport.ReportEmbeddedResource

// add parameters, datasource, etc.

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;

byte[] bytes;
bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

// save byte[] to file with FileStream or something else

However it can render only PDF and XLS (as ReportViewer control cannot export to Word and others as Reportig Service can).

I forgot to mention that the above code is C#, using .NET framework and ReportViewer control. Check out GotReportViewer for a quickstart.

like image 23
Biri Avatar answered Oct 26 '22 23:10

Biri