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指令或程序集引用?)
以及* *你有适当的'using'指令和组装的参考? – 2012-07-21 21:15:32
不,我不知道我应该使用哪一个好心告诉我 – 2012-07-21 21:25:05
@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