【问题标题】:Gridview, itextsharp and pdfGridview、itextsharp 和 pdf
【发布时间】: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]()

【问题讨论】:

    标签: asp.net pdf gridview


    【解决方案1】:

    sr 的内容要么为空,要么HTMLWorker 无法解释其中包含的HTML

    注意:另外,HTMLWorker 类已弃用。

    【讨论】:

      【解决方案2】:

      试试

        GridView1.RenderControl(HtmlTextWriter's object) 
      

      了解更多here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-25
        • 2012-08-18
        • 1970-01-01
        • 1970-01-01
        • 2013-09-02
        相关资源
        最近更新 更多