【问题标题】:Value of type 'iTextSharp.text.Document' cannot be converted to 'System.IO.Stream'“iTextSharp.text.Document”类型的值无法转换为“System.IO.Stream”
【发布时间】:2014-11-12 06:51:11
【问题描述】:

我正在使用 iTextSharp 生成 PDF。但问题是我的代码在 c# 中运行良好,但是当我在 vb 中转换该代码时,它显示 2 个错误

请忽略一些额外的编码和 cmets 我正在使用的代码

 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]()

还有错误

最后编辑的图像:

我该怎么办?

【问题讨论】:

  • 您使用的是哪个版本的 XML Worker?
  • 第三个参数应该是stream 吗?因为StringReader 不是stream。如果您需要将字符串转换为流,请执行以下操作:stackoverflow.com/questions/1879395/…
  • XML 5.5.3.0 版本
  • 在(已删除的)cmets 中,您声称您使用的是 5.1.2。现在你说你使用的是 5.5.3。首先确保您对 iTextSharp XML Worker 都使用 5.5.3。然后看看@dbc 发表的评论:你需要一个stream,而不是一个reader。您的问题是由不良的编码卫生引起的。请重新开始(从头开始,使用干净的项目)。
  • Yap U 得到了解决方案有版本问题谢谢@Bruno 和所有

标签: c# vb.net itextsharp


【解决方案1】:

我有同样的问题。

【讨论】:

    猜你喜欢
    • 2013-07-06
    • 2018-07-06
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 2019-05-15
    相关资源
    最近更新 更多