Export ASP.Net GridView with Background colors to PDF using iTextSharp

govind
 
on Sep 21, 2012 04:39 AM
10414 Views

Hi,

i want  print gridview in pdf format .print successfull but print without background color, header ,coloumn, and row

 i am using following code :

 

 protected void Button3_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Govind.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.ShowHeader = true;
        GridView1.AllowPaging = false;
        SqlCommand cmd = new SqlCommand("Select top 10 * from   tbl_StudentRegistration", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        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.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();
    }


Thanks & Regards

 Govind Jangir

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Mudassar
 
on Sep 21, 2012 04:40 AM

If you need background colors download the sample from

Export ASP.Net GridView to PDF with Custom Columns Widths using iTextSharp

And look for the DLL in the BIN folder

govind
 
on Sep 21, 2012 05:27 AM

hi,

Your suggested article is not working properly.

itextsharp.text.Table  is not present in this namespace.

if you another idea then tell me .it's urgent

 thanks & regards

 

Govind Jangir