title: How to flatten fields with the same names
body: <p>I'm using <code>itext 7.1.8</code> and I need to flatten a document that contains fields with the same names.<br/>
  I create the document like the following:</p>
  <pre><code>private static PdfDocument createPdfDocument(final String name, final int countFields) {
          PdfDocument pdf;
          try {
              final FileOutputStream os = new FileOutputStream(name + &quot;.pdf&quot;);
              PdfWriter pdfWriter = new PdfWriter(os);
              pdf = new PdfDocument(pdfWriter);
  
  
              final PdfPage pdfPage = pdf.addNewPage();
  
              final float height = pdfPage.getCropBox().getHeight();
  
              final PdfTextFormField txt1Fld = PdfFormField.createText(pdf, new Rectangle( 100, height - 100, 200, 18), &quot;Text_1&quot;);
              txt1Fld.setValue(&quot;Hello&quot;);
  
              for (int i = 0; i &lt; countFields; i++) {
                  PdfAcroForm.getAcroForm(pdf, true)
                          .addField(txt1Fld, i == 0 ? pdfPage : pdf.addNewPage());
              }
  
              pdf.close();
          } catch (Exception e) {
              e.printStackTrace();
              pdf = null;
          }
          return pdf;
      }
  </code></pre>
  <p>after that, I'm trying to flatten document like the following:</p>
  <pre><code>private static void flattenPdf(String name, String flattenName) {
          try {
              OutputStream os = new FileOutputStream(flattenName + &quot;.pdf&quot;);
              InputStream is = new FileInputStream(name + &quot;.pdf&quot;);
              PdfReader reader = new PdfReader(is);
              PdfWriter writer = new PdfWriter(os);
              final PdfDocument pdfDocument = new PdfDocument(reader, writer);
              final PdfAcroForm acroForm = PdfAcroForm.getAcroForm(pdfDocument, true);
              acroForm.setNeedAppearances(true);
              acroForm.flattenFields();
              pdfDocument.close();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  <p>There is my main method:</p>
  <pre><code>public static void main(String[] args) throws IOException {
      final String flattenName = &quot;ItextPdfTwoFields&quot;;
  
      System.out.println(&quot;Create &quot; + flattenName + &quot;.pdf&quot;);
      createPdfDocument(flattenName, 2);
      System.out.println(flattenName + &quot;.pdf created successfully&quot;);
      System.out.println(&quot;Trying to flat &quot; + flattenName + &quot;_flatten.pdf...&quot;);
      flattenPdf(flattenName, flattenName + &quot;_flatten&quot;);
  }
  </code></pre>
  <p>and after flattening I get the document which contains one flatten fields but I have to get two flatten fields.<br/>
  How can I fix this issue?</p>