Last post Apr 27, 2011 01:27 PM by n00raina
Member
68 Points
126 Posts
Apr 26, 2011 08:31 AM|n00raina|LINK
I am unable to export GridView to PDF
HtmlForm frm = new HtmlForm(); StringWriter sw = new StringWriter(); HtmlTextWriter hTextWriter = new HtmlTextWriter(sw); GridView1.Parent.Controls.Add(frm); frm.Attributes["runat"] = "server"; frm.Controls.Add(GridView1); try { frm.RenderControl(hTextWriter); } catch (Exception) { } Document Doc = new Document(); Doc.Open(); StringReader sr = new StringReader(sw.ToString()); Response.AddHeader("content-disposition", attachment;filename=Export.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/pdf"; HTMLWorker HtmlParser = new HTMLWorker(Doc); HtmlParser.Parse(sr); Doc.Close(); Response.Write(Doc); Response.End();
The error is "Adobe Reader cannot open the pdf either it is corrupted or not supported type . . . ."
Apr 27, 2011 03:00 AM|n00raina|LINK
Is there anyone who can help me . . ???It's for learning purpose guys.
Contributor
2231 Points
727 Posts
Apr 27, 2011 03:19 AM|suresh dasari|LINK
hi that problem with itextsharp dll check this post and dowload the attached code and use the dll whatever i used in my code it will solve ur problem
http://aspdotnet-suresh.blogspot.com/2011/04/how-to-export-gridview-data-to-pdf.html
Apr 27, 2011 08:31 AM|n00raina|LINK
Hi thanks for reply but I am getting this error . .
suresh dasari RegisterForEventValidation can only be called during Render();
RegisterForEventValidation can only be called during Render();
Apr 27, 2011 11:33 AM|suresh dasari|LINK
hi can u please check my post clearly i explained clearly how to solve that problem registerforeventvalidation also in post
Apr 27, 2011 01:27 PM|n00raina|LINK
suresh dasari hi can u please check my post clearly i explained clearly how to solve that problem registerforeventvalidation also in post
Ok, thanks I got it . . . . . It helped me a lot, thanks to you
Member
68 Points
126 Posts
Using iTextSharp and still getting corrupted pdf
Apr 26, 2011 08:31 AM|n00raina|LINK
I am unable to export GridView to PDF
The error is "Adobe Reader cannot open the pdf either it is corrupted or not supported type . . . ."
Member
68 Points
126 Posts
Re: Using iTextSharp and still getting corrupted pdf
Apr 27, 2011 03:00 AM|n00raina|LINK
Is there anyone who can help me . . ???It's for learning purpose guys.
Contributor
2231 Points
727 Posts
Re: Using iTextSharp and still getting corrupted pdf
Apr 27, 2011 03:19 AM|suresh dasari|LINK
hi that problem with itextsharp dll check this post and dowload the attached code and use the dll whatever i used in my code it will solve ur problem
http://aspdotnet-suresh.blogspot.com/2011/04/how-to-export-gridview-data-to-pdf.html
Member
68 Points
126 Posts
Re: Using iTextSharp and still getting corrupted pdf
Apr 27, 2011 08:31 AM|n00raina|LINK
Hi thanks for reply but I am getting this error . .
Contributor
2231 Points
727 Posts
Re: Using iTextSharp and still getting corrupted pdf
Apr 27, 2011 11:33 AM|suresh dasari|LINK
hi can u please check my post clearly i explained clearly how to solve that problem registerforeventvalidation also in post
Member
68 Points
126 Posts
Re: Using iTextSharp and still getting corrupted pdf
Apr 27, 2011 01:27 PM|n00raina|LINK
Ok, thanks I got it . . . . . It helped me a lot, thanks to you