简体   繁体   中英

Render SSRS report in PDF format in ASP.NET

I have some deployed SSRS reports on the server. Now I am accessing those reports from my ASP.NET application. After some research I found that default print button of the ReportViewer will not be visible in Chrome or any web browser except Internet Explorer. So all I want to render the Reports in PDF format so user can take the print out of PDF format without saving the file. Here's the piece of code I am using:

IReportServerCredentials irsc = DBConnection.NetworkCredentials();
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
List<ReportParameter> list = new List<ReportParameter>();
list.Add(new ReportParameter("ref_no", refNo));
ReportViewer1.ServerReport.SetParameters(list);
ReportViewer1.ServerReport.Render("PDF");
ReportViewer1.ServerReport.Refresh();

But its not working. The reports are getting rendered but not in PDF format. And if someone take the print out, alignment of all the fields like Tablix, TextBox are not properly aligned. Does any one know how can I do this?

Fortunately, after so many try, have found the solution. This is what I have done:

IReportServerCredentials irsc = DBConnection.NetworkCredentials();
ReportViewer1.ServerReport.ReportServerCredentials = irsc;

List<ReportParameter> list = new List<ReportParameter>();
list.Add(new ReportParameter("ref_no", refNo));
ReportViewer1.ServerReport.SetParameters(list);
byte[] data = ReportViewer1.ServerReport.Render("pdf");
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline;filename=Manifest_Print.pdf");
Response.BinaryWrite(data);

And it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM