问题描述
基本原理是,我尝试使用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,它只需要有人指出对我来说很明显。解决该问题的任何帮助将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)