title: iTextSharp file manipulation and display to FileStreamResults
body: <p>I am trying top open a PDF file using iTextSharp, add a dataset to the file to prepopulate data, then save it to a stream so that I can display it to the users.  I don't want to save it locally to a file. I keep getting the error "Cannot access a closed Stream." I can't figure out which stream is wrong.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public FileStreamResult PushDataIntoPDFStream(string filename)
  {     
       var reader = new PdfReader(Path.Combine(Server.MapPath(path), filename));
       var xml = @"&lt;?xml version=""1.0"" encoding=""UTF-8""?&gt;
            &lt;form1&gt;  
               &lt;firstName&gt;test&lt;/firstName&gt;
               &lt;lastName&gt;user&lt;/lastName&gt;
               &lt;driveCar&gt;0&lt;/driveCar&gt;
               &lt;gender&gt;1&lt;/gender&gt;
               &lt;birthdate&gt;2011-08-12&lt;/birthdate&gt;
               &lt;numPets&gt;4&lt;/numPets&gt;
            &lt;/form1&gt;";
  
       using (var outstream = new MemoryStream())
       { 
            using (var stamper = new PdfStamper(reader, outstream))
            {
                 var bytes = System.Text.Encoding.UTF8.GetBytes(xml);
                 using (var ms = new MemoryStream(bytes))
                 {
                      stamper.AcroFields.Xfa.FillXfaForm(ms);
                 }
            }
  
            return new FileStreamResult(outstream, "application/pdf")
            {
                  FileDownloadName = "file.pdf";
            };
       }      
    }
  </code></pre>