asp.net - 尝试将 gridview 转换为 PDF 文档
问题描述
基本原则是我试图将 GridView 转换为 PDF 文档。GridView 包括复选框等控件和一些带有一些颜色的 css 类。
我试过把它放在一起,但我想我误解了一些东西是如何工作的,现在走到了死胡同。目前它全部编译并运行,但是当您尝试打开返回的 PDF 时,它说它无法加载。返回的文件大小为 1KB,所以我猜它实际上不是有效的 PDF。
我正在使用 iText7 和 htmlPDF,我的代码看起来像这样。
Protected Sub ExportToPDF(sender As Object, e As ImageClickEventArgs)
Using sw As New StringWriter()
Using hw As New HtmlTextWriter(sw)
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
gvCSC.DataBind()
gvCSC.RenderControl(hw)
Dim pdfWriter As New PdfWriter(Response.OutputStream)
Dim pdfDoc As New PdfDocument(pdfWriter)
Dim sr As New StringReader(sw.ToString)
pdfDoc.SetDefaultPageSize(New PageSize(PageSize.A4.Rotate))
Dim doc As Document = HtmlConverter.ConvertToDocument(sr.ToString, pdfDoc, New ConverterProperties)
Response.End()
pdfDoc.Close()
End Using
End Using
End Sub
我希望我只是愚蠢,因为我以前没有使用过 iText7,它只需要有人指出对我来说显而易见的事情。解决此问题的任何帮助将不胜感激。
解决方案
推荐阅读
- android - 将离子安装到 android 设备时出现 Cordova 错误
- linux - 在 shell 脚本中传递 N 个参数
- c++ - 带有宏的旧式 C 标头的旧式强制转换(C 强制转换)上的 g++ 警告
- python - ImportError: undefined symbol - 当我在 C 的扩展中实现 Opengl 代码和 Tkinter 时
- algorithm - 昂贵的卷帘窗产品的有效总和
- bash - 递归删除文件夹和子文件夹中的文件
- opencv - 获取不同级别的图像边缘
- django - 如何使用 CreateView 将用户对象传递给 Modelform
- ansible - 使用 Vagrant 测试 ansible 角色
- c# - 无法读取文档开头带有字符的 XML 文件