GridView Data to PDF File



In this post You find GridView Data to PDF File in asp.net

using iTextSharp.text;

using iTextSharp.text.pdf;

using iTextSharp.text.html.simpleparser;

using System.IO;

---------------------

Button Click Coding ( PDF Conversion )

---------------------

        Response.ContentType = "application/pdf";

        Response.AddHeader("content-disposition", "attachment;filename=GridViewData.pdf");

        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        StringWriter sw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GridView1.AllowPaging = false;

        GridView1.DataBind();

        GridView1.RenderControl(hw);

        StringReader sr = new StringReader(sw.ToString());

        Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);

        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

        pdfDoc.Open();

        htmlparser.Parse(sr);

        pdfDoc.Close();

        Response.Write(pdfDoc);

        Response.End();

        ---------------------------

public override void VerifyRenderingInServerForm(Control control)

    {

        /* Verifies that the control is rendered */

    }

0 Comment's

Comment Form

Submit Comment