我正在使用 iTextSharp 生成 PDF。但问题是我的代码在 c# 中运行良好,但是当我在 vb 中转换该代码时,它显示 2 个错误
请忽略一些额外的编码和注释 我正在使用的代码
Dim Response As HttpResponse = SelectedGridView.Page.Response
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=" & FileName)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
SelectedGridView.RenderControl(hw)
Dim sr As New StringReader("<html><body>" & sw.ToString() & "</body></html>")
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim pdfWrite As PdfWriter = Nothing
pdfWrite = PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
Try
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWrite, pdfDoc, sr)
Catch ex As Exception
End Try
'htmlparser.Parse(sr);
pdfDoc.Close()
Response.Write(pdfDoc)
Response.[End]()
错误
最后编辑的图片:
我该怎么办?
最佳答案
我遇到了同样的问题。
我从 http://sourceforge.net/projects/itextsharp/?source=typ_redirect 下载了 iTextSharp 的 dll 文件和来自 http://sourceforge.net/projects/itextsharp/files/xmlworker/ 的 xmlworker
提取它们并右键单击解决方案资源管理器中的解决方案,然后添加 -> 引用并在浏览选项卡中添加您的 dll 文件。
关于c# - 类型 'iTextSharp.text.Document' 的值无法转换为 'System.IO.Stream',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26880946/