写一个GridView到.pdf文件 [英] Write a GridView to a .pdf file
本文介绍了写一个GridView到.pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一个GridView,GV为.pdf文件。
经与pdfDoc问题。
Response.ContentType =应用程序/ PDF
Response.AddHeader(内容处置,附件;文件名= Export.pdf)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
昏暗SW作为新的StringWriter()
昏暗的硬件作为新的HtmlTextWriter(SW)
昏暗FRM作为新的HtmlForm()
gv.Parent.Controls.Add(FRM)
frm.Attributes(RUNAT)=服务器
frm.Controls.Add(GV)
frm.RenderControl(HW)
昏暗SR作为新StringReader(sw.ToString())
昏暗pdfDoc作为新文档(PageSize.A4,10.0F,10.0F,10.0F,0.0F)
昏暗的HTMLParser作为新HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc,Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(SR)
pdfDoc.Close()
的Response.Write(pdfDoc)
响应。[完]()
解决方案
你为什么不通过你的GridView行或数据源的项目循环并创建一个HTML字符串?
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]()
解决方案
Why don't you loop through your Gridview rows or your datasource items and create an html string?
这篇关于写一个GridView到.pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文