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

大城市里の小女人 提交于 2019-12-05 00:20:33

问题


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.


回答1:


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



回答2:


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.




回答3:


Can you pass a .rdlc report directly to pdf with parameters? I have two dropdownlists that i pull my report with. I can't get the parameters to work when automatically exporting to pdf. Here is the error I get: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: One or more parameters required to run the report have not been specified.

The dropdownlists work when I use the reportviewer, but i want to skip this step. I can also get my data to go directly to a pdf if it doesn't have any parameters. My dropdownlists are called ddlyear and ddlmonth.



来源:https://stackoverflow.com/questions/138203/how-to-generate-a-pdf-from-an-embedded-report-definition-without-server-or-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!