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 writer 和 Paragraph 有同样的错误

4

1 回答 1

2

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

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

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

using iTextSharp.text; 

using iTextSharp.text.pdf;

iTextSharp.text 负责 Document Object

于 2013-08-20T10:30:16.960 回答