【问题标题】:Document cannot be converted into iTextSharp.text.Document文档无法转换为 iTextSharp.text.Document
【发布时间】:2025-12-30 15:45:12
【问题描述】:

所以我在 codeproject http://www.codeproject.com/Articles/20640/Creating-PDF-Documents-in-ASP-NET 看到了这个教程。我在我的网络项目中使用了 itextsharp

  Dim doc As Document = New Document
     PdfWriter.GetInstance(doc, New FileStream("C:\Users\PC\Desktop" + _
                                 "\1.pdf", FileMode.Create))

            doc.Open()
            doc.Add(New Paragraph("Hello World"))
            doc.Close()
            Response.Redirect("~/1.pdf")

使用这种语法,我得到错误,“myProjectName.Document”无法转换为“iTextSharp.text.Document”并且打开、添加、关闭不是“myProjectName.Document”的成员

我当前的框架是 3.5 。我已经下载了示例项目,它是框架 2.0,但当我将其更改为 3.5 时仍然可以运行,

我的问题有什么解决方法吗?

【问题讨论】:

    标签: asp.net vb.net pdf itextsharp document


    【解决方案1】:

    看起来您的 Document 来自其他命名空间,请尝试明确指定命名空间:

    dim doc as iTextSharp.text.Document = new iTextSharp.text.Document()  'may need parameters to constructor
    

    【讨论】: