Avatar of jknj72
jknj72
 asked on

Export to pdf

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()

Open in new window

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
jknj72

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ramkisan Jagtap

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jknj72

ASKER
thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck