Có thể tạo tài liệu PDF trong bộ nhớ với iTextSharp cho phép người dùng lựa chọn "mở" hoặc "lưu" ?, và nếu nó mở ra thì nó sẽ mở ra trong cửa sổ trình duyệt.mở tài liệu PDF từ bộ nhớ
Hiện tại, tôi chỉ lưu nó vào đĩa.
CHỈNH SỬA:
ok Tôi đã lo lắng. Tôi đã kết thúc việc phải ghi tập tin vào một thư mục, nhưng nó chỉ là tạm thời khi bị ghi đè mỗi lần. Dưới đây là giải pháp cho những gì nó có giá trị:
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();
}
Hãy xem xét đăng giải pháp của bạn làm câu trả lời và đánh dấu nó là được chấp nhận. – dckuehn