问题
I am trying to write a GridView, gv to a .pdf file.
Having problems with pdfDoc.
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=Export.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
Dim frm As New HtmlForm()
gv.Parent.Controls.Add(frm)
frm.Attributes("runat") = "server"
frm.Controls.Add(gv)
frm.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New 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]()
回答1:
Why don't you loop through your Gridview rows or your datasource items and create an html string?
来源:https://stackoverflow.com/questions/23897937/write-a-gridview-to-a-pdf-file