Export Gridview Data To PDF Format

using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;

Protected void btnGView to pdfclick(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.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.A4, 10f,10f,10f,0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}


Now we need to be made sure regarding the iTextSharp Library which does not support background color of table cells or table rows.
Hence while rendering it to the pdf format we need to modify the iTextSharp so that it exports the HTML with background color.

We have already modified the iTextSharp Library DLL so that the GridView is rendered with all the background color used.

1 Comments

  1. hi,

    i am facing same problem of background color.

    can you please mail me updated itextsharp dll?

    that will be very helpful to me.

    my mail id is coolsun03@gmail.com

    Thanks,
    Mahavir Shah
    093289 35308

    ReplyDelete

Post a Comment

Previous Post Next Post