locked
gridview to pdf using itextsharp RRS feed

  • Question

  • User-1118395791 posted

    hi,

    when i am coverting my gridview to pdf it is giving the correct output but the data in pdf is page is missing with the header text always and also not showing all the columns of the gridview..this is really a problem please help!!! 

    below is the code for export to pdf:

    using (StringWriter sw = new StringWriter())
                {
                    using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                    {
                        //To Export all pages
                        GridView1.AllowPaging = false;
                        this.BindGrid();
    
                        GridView1.RenderControl(hw);
                        StringReader sr = new StringReader(sw.ToString());
                        Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
                        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                        pdfDoc.Open();
                        htmlparser.Parse(sr);
                        pdfDoc.Close();
    
                        Response.ContentType = "application/pdf";
                        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
                        Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        Response.Write(pdfDoc);
                        Response.End();
                    }

    below is the code of gridview in aspx:

    <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
            RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
            runat="server" AutoGenerateColumns="false" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" ItemStyle-Width="50px" />
                <asp:BoundField DataField="Complaint_id" HeaderText="Complaint ID" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Registered_by" HeaderText="Registered BY" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Customer" HeaderText="Customer" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Status" HeaderText="Status" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Category" HeaderText="Category" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Sub_Category" HeaderText="Sub_Category" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Items" HeaderText="Items" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Start_Date" HeaderText="Start Date" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Title" HeaderText="Title" ItemStyle-Width="150px" />
                <asp:BoundField DataField="Engineer_on_site" HeaderText="Engineer on site" ItemStyle-Width="100px" />
                  <asp:BoundField DataField="Location" HeaderText="Location" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Engineer_on_call" HeaderText="Engineer_on_call" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Priority" HeaderText="Priority" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Closed_date" HeaderText="Closed_date" ItemStyle-Width="100px" />
                <asp:BoundField DataField="Description" HeaderText="Description" ItemStyle-Width="100px" />
            </Columns>
        </asp:GridView>




    Tuesday, October 15, 2013 1:46 AM

Answers

All replies