Save SSRS reports to a PDF from .Net code without rendering it in a ReportViewer

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi
I have a requirement whereby I need to allow the users to select multiple reports from a list of reports and then print all the selected reports to a single PDF file together without rendering the reports on the .Net page. What I mean to say is, I am giving
the users a list of reports with a checkbox against each report name. The user can select multiple reports by ticking the checkboxes. When the user clicks on the "Print Reports" button, all the selected reports must be generated in the backend and the content
of all the reports must be saved to a single PDF file.
I was successful in creating the PDF file but the problem is that only contents of one report are getting written to the file. I am taking byte arrays for each report, saving the content of the report into the byte array and combining the byte arrays into
a single byte array at the end and writing the combined array into the PDF. While debugging, I can see that the combined array has the contents of all the reports, but the final PDF shows the contents of the last report only. I do not understand where I am
going wrong.


<pre class="prettyprint" style=" Microsoft.Reporting.WebForms.Warning warnings;
string fileName = "test";
string streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Remote;
viewer.ServerReport.ReportServerUrl = new Uri("http://server/ReportServer_SQL2008R2");
viewer.ServerReport.ReportPath = "/Reports/BalanceRangesReport";

ReportViewer viewer1 = new ReportViewer();
viewer1.ProcessingMode = ProcessingMode.Remote;
viewer1.ServerReport.ReportServerUrl = new Uri("http://server/ReportServer_SQL2008R2");
viewer1.ServerReport.ReportPath = "/Reports/GeographicBreakdownReport3";

Byte[] bytes = viewer.ServerReport.Render("PDF");
Byte[] bytes1 = viewer1.ServerReport.Render("PDF");

Byte[] resultBytes = Combine(bytes, bytes1);

Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", ("attachment; filename=" + fileName + ".") + extension);
Response.BinaryWrite(resultBytes);
Response.Flush();[/code]
<br/>
As mentioned earlier, the byte array resultbytes seems to have data from both the reports when we are debugging the application, but the saved PDF shows only the data from the second report. Please help.<br/>

Thanks
NModi

<br/>

View the full article
 
Back
Top