title: How to return PDF to browser in MVC?
body: <p>I have this demo code for iTextSharp</p>
  
  <pre><code>    Document document = new Document();
      try
      {
          PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.Create));
  
          document.Open();
  
          document.Add(new Paragraph("Hello World"));
  
      }
      catch (DocumentException de)
      {
          Console.Error.WriteLine(de.Message);
      }
      catch (IOException ioe)
      {
          Console.Error.WriteLine(ioe.Message);
      }
  
      document.Close();
  </code></pre>
  
  <p>How do I get the controller to return the pdf document to the browser?</p>
  
  <p>EDIT:</p>
  
  <p>Running this code does open Acrobat but I get an error message "The file is damaged and could not be repaired"</p>
  
  <pre><code>  public FileStreamResult pdf()
      {
          MemoryStream m = new MemoryStream();
          Document document = new Document();
          PdfWriter.GetInstance(document, m);
          document.Open();
          document.Add(new Paragraph("Hello World"));
          document.Add(new Paragraph(DateTime.Now.ToString()));
          m.Position = 0;
  
          return File(m, "application/pdf");
      }
  </code></pre>
  
  <p>Any ideas why this does not work?</p>