Export ASP.Net GridView with Company logo to PDF using C# and VB.Net in ItextSharp

Last Reply 8 months ago By pandeyism

Posted 8 months ago

I have a Gridview control populated from code behind and when I do the PDF export on button click I would like to place the company logo above the gridview control.

This is my current code to export the gridview to PDF:

        Try
            Using sw As New StringWriter()
                Using hw As New HtmlTextWriter(sw)
                    'To Export all pages
                    GridView1.AllowPaging = False
                    Me.LoadDataGrid()
                    GridView1.RenderControl(hw)
                    Dim sr As New StringReader(sw.ToString())
                    Dim pdfDoc As New Document(PageSize.A2, 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.ContentType = "application/pdf"
                    Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf")
                    Response.Cache.SetCacheability(HttpCacheability.NoCache)
                    Response.Write(pdfDoc)
                    Response.[End]()
                End Using
            End Using
        Catch ex As Exception
        End Try

 

This question does not have replies that have been liked.