How to export GridView data to pdf file in Asp.net and C #?

I am currently facing the tedious problem of exporting the complete GridView data to a pdf file so that the user can save it. I am using C # as the language in Asp.net 3.5. Please help me.

The grid contains only text values.

Thanks in advance.

+2


a source to share


3 answers


Exporting GridView to Pdf using iTextSharp ASP.NET
Exporting GridView to PDF



I didn't do it myself.

+3


a source


nFOP + XSLT + XML = pdf | doc | Html

open source no cost :)



TO

+1


a source


public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}

protected void GeneratePDF_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.AllowPaging = false;
    GridView1.DataBind();
    GridView1.RenderControl(hw);
    GridView1.HeaderRow.Style.Add("width", "15%");
    GridView1.HeaderRow.Style.Add("font-size", "10px");
    GridView1.Style.Add("text-decoration", "none");
    GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
    GridView1.Style.Add("font-size", "8px");
    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();   
}

      

0


a source







All Articles