2012-07-21 48 views
0
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作家同样的错误和段落错误类型或命名空间名称“文件”找不到(是否缺少using指令或程序集引用?)

+3

以及* *你有适当的'using'指令和组装的参考? – 2012-07-21 21:15:32

+0

不,我不知道我应该使用哪一个好心告诉我 – 2012-07-21 21:25:05

+0

@ArslanSunny:看起来像你使用iTextSharp。请参考您项目中的dll并使用相关的iTextSharp命名空间。 CTRL +。将帮助你。也读这个。 http://www.mikesdotnetting.com/Article/80/Create-PDFs-in-ASP.NET-getting-started-with-iTextSharp – naveen 2012-07-21 21:27:53

回答

1

我有同样的问题是,然后我找到了答案

首先要安静确保iTextSharp.dll添加引用,并在主窗体的起点

然后。收藏此

using iTextSharp.text; 

using iTextSharp.text.pdf; 

iTextSharp.text负责文档对象

相关问题