I have a gridview user control and I am trying to Export the gridview data to a pdf. It seems that the fact that the grid is in a user control that the code that I am trying to use is not working? I dont know if this is the reason, I can only speculate from all the things Ive seen out there and nothing is working? Anybody have a clue what it could be?
Ive tried 10 different code snippets and none has worked.
This was the latest code I tried:
'PDF Response.Clear() Response.Buffer = True Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "attachment;filename=gridTest.pdf") Response.Cache.SetCacheability(HttpCacheability.NoCache) Dim sw As New StringWriter() Dim hw As New HtmlTextWriter(sw) myGridview.AllowPaging = False Dim frm As New HtmlForm() myGridview.Parent.Controls.Add(frm) frm.Attributes("runat") = "server" frm.Controls.Add(myGridview) frm.RenderControl(hw) myGridview.DataBind() Dim sr As New StringReader(sw.ToString()) Dim pdfDoc As New iTextSharp.text.Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F) Dim htmlparser As New HTMLWorker(pdfDoc) PdfWriter.GetInstance(pdfDoc, Response.OutputStream) pdfDoc.Open() htmlparser.Parse(sr) pdfDoc.Close() Response.Write(pdfDoc) Response.End()