How to print RDLC Report in ASP.Net

Last Reply on Aug 18, 2012 04:20 AM By Mudassar

Posted on Aug 18, 2012 04:15 AM
hi
I'm using .rdlc report in my **web application**, exporting report to pdf & print it works great but now i wanted to print report automatically(i,e on click of print button.)

    Is it possible to print rdlc report automatically?
please send me code how to print report  on click of print button. 
Please help me,
Thanks
Bablu 
jaipur
Add code
.................
 protected void Print_Click(object sender, EventArgs e)
    {

        string recordIdCount = "201";
        Print(recordIdCount);

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

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

        FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("SchoolData/image/output.pdf"), FileMode.Create);
        fs.Write(bytes, 0, bytes.Length);
        fs.Close();
        //Open exsisting pdf
        Document document = new Document(PageSize.LETTER);
        PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("SchoolData/image/output.pdf"));
        //Getting a instance of new pdf wrtiter
        PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.
          Server.MapPath("SchoolData/image/Print.pdf"), FileMode.Create));
        document.Open();
        PdfContentByte cb = writer.DirectContent;
        int i = 0;
        int p = 0;
        int n = reader.NumberOfPages;
        Rectangle psize = reader.GetPageSize(1);
        float width = psize.Width;
        float height = psize.Height;
        //Add Page to new document
        while (i < n)
        {
            document.NewPage();
            p++;
            i++;

            PdfImportedPage page1 = writer.GetImportedPage(reader, i);
            cb.AddTemplate(page1, 0, 0);
        }

        //Attach javascript to the document
        PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer);
        writer.AddJavaScript(jAction);
        document.Close();
        //Attach pdf to the iframe
        frmPrint.Attributes["src"] = "SchoolData/image/Print.pdf";

    }
Posted on Aug 18, 2012 04:20 AM Modified on on May 05, 2014 06:23 AM

Please add a button using onClientClick of the Button you can Print the report.

Reference:

RDLC (Local SSRS) Report ASP.Net Example using DataSet or DataTable in C# VB.Net and Visual Studio 2010

HTML:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
        function PrintPanel() {
            var panel = document.getElementById("<%=pnlContents.ClientID %>");
            var printWindow = window.open('', '', 'height=400,width=800');
            printWindow.document.write('<html><head>');
            printWindow.document.write('</head><body >');
            printWindow.document.write(panel.innerHTML);
            printWindow.document.write('</body></html>');
            printWindow.document.close();
            setTimeout(function () {
                printWindow.print();
            }, 500);
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Panel ID="pnlContents" runat="server">
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="600">
        </rsweb:ReportViewer>
    </asp:Panel>
    <asp:Button ID="PrintButton" Text="Print" runat="server" OnClientClick="return PrintPanel();" />
    </form>
</body>
</html>

C# code remains same. You can download it from the reference link.

Image:

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html