类型的价值' iTextSharp.text.Document'无法转换为' System.IO.Stream'

时间:2014-11-12 06:51:11

标签: c# vb.net itextsharp

我使用iTextSharp生成PDF。但问题是我的代码在c#中正常工作但是当我在vb中转换该代码时它会显示2个错误

请忽略一些额外的编码和评论 代码i使用

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

和错误

enter image description here

上次修改图片:

enter image description here 我该怎么办?

1 个答案:

答案 0 :(得分:0)

我有同样的问题。