【发布时间】:2014-08-21 05:00:26
【问题描述】:
使用 itextsharp.dll 作为参考和在下面的代码之前定义的 Gridview 我不断收到错误:
The document has no pages.
代码如下:
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=this.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
Dim frm As New HtmlForm()
GridView1.AllowPaging = False
GridView1.Parent.Controls.Add(frm)
frm.Attributes("runat") = "server"
frm.Controls.Add(GridView1)
frm.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim PDFdoc As New Document(PageSize.A2, 7.0F, 7.0F, 7.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]()
【问题讨论】: