You can create a PDF document in memory with iTextSharp that gives the user the option to “open” or “save” ?, and if it opens, it opens in a browser window.
At the moment, only I saved it to disk.
EDIT:
ok I have it crazy. I still had to write the file to a folder, but it is temporary, as it is overwritten every time. Here is a solution for what it costs:
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;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=myPDF.pdf");
Response.TransmitFile(filepath);
Response.End();
}
source
share