Transforming the report output into PDF is an easy task now.
Sql Server Reporting service has got a wonderful option called export which in fact helps to export the report output to PDF or Excel. However unfortunately it does not allow user to generate any specific type of output like PDF or excel. So in this article we are going to see how to create only PDF file from the report output.
To transform a RDLC report output to a pdf file
1.Create a SSRS RDLC Report
2.Create Function Which can convert Report output to PDF
Using the code In this code we are going to create a report to show top 20 employee details.After the report is created, it needs to be converted to pdf manually. So in the under mentioned code the export control is removed ,intentionally ,by using ShowExportControls=false.
The getData() method of the code behind populates employee details in the report-viewer.
When one clicks on Export2PDF button the output of Report-Viewer gets converted to PDF and the user is asked to save the file to physical location .
In this code I have marked a commented section which means the pdf can also be saved to any specified disk location provided permission is granted to the user.
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Export2PDF" Width="106px" />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" ShowExportControls="false"
Font-Size="8pt" Height="400px" Width="100%">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
</form> // Code Behind string connn = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
protected void getData()
SqlDataAdapter da = new SqlDataAdapter("select top 20 * from Employees", connn);
DataSet ds = new DataSet();
ReportDataSource rdc = new ReportDataSource("DataSet1_Employees", ds.Tables);
ReportViewer1.Visible = true;
protected void Button1_Click(object sender, EventArgs e)
byte bytes = this.ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
// writing to disk
//FileStream fs = new FileStream(@"c:\ReportOutput.pdf", FileMode.Create);
//FileStream fs = new FileStream(Server.MapPath(@"pdfs\abc.pdf"), FileMode.Create);
//fs.Write(bytes, 0, bytes.Length);
When user first loads the page ,the getData() method is called,which takes care of loading employee details in the report-viewer. Here you cannot see any export option since it is made to false as i mention earlier in this article. To create a pdf this , user needs to click on Export2PDF button.
After clicking on Export2PDF button , user is asked to save the file to a physical location as shown in the figure.
This is how a PDF can be created manually from SSRS- RDLC Report output.