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
有同样的错误答案 0 :(得分:1)
我遇到同样的问题然后我找到了答案
首先要确保将iTextSharp.dll添加到引用和
然后在主窗体的开头。添加此
using iTextSharp.text;
using iTextSharp.text.pdf;
iTextSharp.text负责文档对象