Dko*_*ong 5 c# asp.net itextsharp
可以使用iTextSharp在内存中创建PDF文档,使用户可以选择"打开"或"保存"?如果打开则会在浏览器窗口中打开.
目前我唯一将它保存到磁盘.
编辑:
好吧,我已经怀疑了.我最终不得不将文件写入文件夹,但它只是暂时的,因为每次都被覆盖.以下是它的价值所在的解决方案:
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();
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
14321 次 |
| 最近记录: |