错误14找不到类型或命名空间名称“Document”(您是否缺少using指令或程序集引用?)

时间:2012-07-21 21:13:26

标签: c# asp.net-mvc-3

Document document = new Document();
            MemoryStream stream = new MemoryStream();
            try
            {
                PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream);
                pdfWriter.CloseStream = false;

                document.Open();
                document.Add(new Paragraph("Hello World"));
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            document.Close();

            stream.Flush(); //Always catches me out
            stream.Position = 0; //Not sure if this is required
            return File(stream, "application/pdf");

我对pdf writer和Paragraph

有同样的错误

1 个答案:

答案 0 :(得分:1)

我遇到同样的问题然后我找到了答案

首先要确保将iTextSharp.dll添加到引用和

然后在主窗体的开头。添加此

using iTextSharp.text; 

using iTextSharp.text.pdf;

iTextSharp.text负责文档对象

相关问题