使用iTextSharp可以在内存中创建一个PDF文档,使用户可以选择“打开”或“保存”,如果它打开,则会在浏览器窗口中打开。从内存中打开PDF文档
目前我唯一将它保存到磁盘。
编辑:
好,我知道了sussed。我最终不得不将文件写入一个文件夹,但它只是每次都被覆盖的临时文件。下面是它的价值的解决方案:
private void GeneratePDF() {
var doc1 = new Document();
string path = Server.MapPath("~/pdfs/");
string filepath = path + "Doc1.pdf";
PdfWriter.GetInstance(doc1, new FileStream(filepath, FileMode.Create));
doc1.Open();
doc1.Add(new Paragraph("A new Document"));
doc1.Add(new Paragraph(DateTime.Now.ToString()));
doc1.Close();
Response.Buffer = false; //transmitfile self buffers
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=myPDF.pdf");
Response.TransmitFile(filepath);
Response.End();
}
考虑发布您的解决方案作为一个答案,将其标记为接受。 – dckuehn 2016-11-23 18:18:32