I have a Html page which is to be converted to PDF on button click . The Problem is I have a Gridview On This Page having set AutoGenerateColumns is true . PDF is generating fine but all the rows in the gridview are not getting generated by pdf. suppose if my grid view contains 1000 rows my PDF generating just 20 to 30 records . how to Overcome this problem . Without using itextsharp all the rows are generating but problem is not styling on generated page.

    <div style="text-align:center; width:100%;">
        <asp:GridView ID="gvViewReports" Width="100%" AutoGenerateColumns="true" ShowHeader="true" CellPadding="5" runat="server" AllowPaging="false">
                <div style="background-color: #e9f8ff;color: #5d9fa9;border: 1px solid #75c7d3; font-family: Arial, sans-serif;font-size: 12px;line-height: 18px;margin-bottom: 15px;position: relative;padding: 14px 40px 14px 18px;">
                    <strong>No Information Available For Search Criteria</strong>
            <HeaderStyle BackColor="#5d9fa9" ForeColor="White" Font-Size="12px" />
            <AlternatingRowStyle BackColor="#f9f9f9" Font-Size="12px" Width="15px"/>
            <RowStyle Font-Size="12px" Width="15px" />

public void GeneratePDF(string text)
        Response.ContentType = "application/pdf";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        writer.PageEvent = new PDFTemp();
        iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
        string fileName = string.Format("{0}{1}",text, DateTime.Now.ToString());
        //string fileName = string.Format("{0}", text);
        Response.AppendHeader("Content-Disposition", "attachment;Filename=" + fileName + ".pdf");

Related posts

Recent Viewed