title: opening PDF document from memory
body: <p>It is possible to create a PDF document in memory with iTextSharp that gives the user a choice to "open" or "save"?, and if it opens then it opens in a browser window.</p>
  
  <p>At the moment the only I have save it to disk.</p>
  
  <p>EDIT:</p>
  
  <p>ok I've got it sussed. I did end up having to write the file to a folder, but it is only temporary as gets overwritten every time. Here is the solution for what it's worth:</p>
  
  <pre><code>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();
  </code></pre>
  
  <p>}</p>