It is very interesting, but even when I added
gvPastCnt.AllowPaging = False
gvPastCnt.DataSource = ViewState("CurrentTable")
gvPastCnt.DataBind()
gvPastCnt.RenderControl(hw)
it would not work with the existing grid. I built a dummy grid and it worked. There is no formating and it does not pick up boolean values, but it is working
Protected Sub ExportToPDF(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPdf.Click
'Get the data from database into datatable
Dim dsPDF As New DataSet
Dim SQL = "SELECT Pasture, LotNo, OnHand, Sex, ActualCount FROM Lots"
Dim LotAdapter As New OleDbDataAdapter(SQL, LocConn)
LotAdapter.Fill(dsPDF)
'Create a dummy GridView
Dim GridView1 As New GridView()
GridView1.AllowPaging = False
GridView1.DataSource = dsPDF.Tables(0)
GridView1.DataBind()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=PastureCount.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
GridView1.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 7.0F, 7.0F, 7.0F, 0.0F)
'pagesize, left margin, right margin, top margin, bottom margin 72 pixels per inch
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
End Sub