Write a GridView to a .pdf file

ぐ巨炮叔叔 提交于 2020-01-16 23:16:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!