title: C# Unable to update the text using itext sharp
body: <p>As per my previous post <a href="https://stackoverflow.com/questions/39559507/itextsharp-to-edit-existing-pdf/39559738?noredirect=1#comment66458215_39559738">ITextsharp to edit existing pdf</a> I am able to save the PDF in interactive manner. After that I started writing the following code to modify the content and save it to a PDF as follow but when I am trying to open the file it is saying <code>There was an error opening in the document. The file is damaged and could not be repaired</code></p>
  
  <p>This is my code</p>
  
  <pre><code>PdfReader reader = new PdfReader(@"E:\\Test.pdf");
  using (MemoryStream memoryStream = new MemoryStream())
  {
      PdfStamper pdfStamper = new PdfStamper(reader, memoryStream, '\0', true);
      pdfStamper.FormFlattening = true;
      AcroFields af = reader.AcroFields;
      string[] fields = pdfStamper.AcroFields.Fields.Select(x =&gt; x.Key).ToArray();
      for (int key = 0; key &lt;= fields.Count() - 1; key++)
      {
        pdfStamper.AcroFields.SetField(fields[key], txtApplicantName.Text);
      }
      Byte[] bytes= memoryStream.ToArray();
      File.WriteAllBytes(@"E:\\Test1.pdf", bytes);
  }
  </code></pre>
  
  <p>Can some one tell me where I am doing wrong</p>