title: inserting pages with PdfStamper does not import form fields
body: <p>I'm inserting pages pages into pdf doc. The pages don't get added at the end or begining they need to be inserted in the middle somewhere (I have a way to determine the insert location with bookmarks).</p>
  
  <p>The key is not to loose bookmarks. So I'm using PdfStamper to insert the pages. The problem is pdfs that are being inserted have form fields and those fields are not coming through. </p>
  
  <p>The code that does inserting</p>
  
  <pre><code>for (int pageNum = 1; pageNum &lt;= readerPdfToAdd.NumberOfPages; pageNum++)
  {
      PdfImportedPage page = pdfStamper.GetImportedPage(readerPdfToAdd, pageNum);
      pdfStamper.InsertPage(filesByCategory[i].PageOfInsert + pageNum, readerPdfToAdd.GetPageSizeWithRotation(pageNum));
  
      var rotation = readerPdfToAdd.GetPageRotation(pageNum);
      if (rotation == 90 || rotation == 270) 
      {
          pdfStamper.GetUnderContent(filesByCategory[i].PageOfInsert + pageNum)
                    .AddTemplate(page, 0, -1f, 1f, 0, 0, readerPdfToAdd.GetPageSizeWithRotation(pageNum).Height);                                          
      }
      else 
      {
          pdfStamper.GetUnderContent(filesByCategory[i].PageOfInsert + pageNum).AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
  
  
      }
  }
  </code></pre>
  
  <p>I tried something like this to copy the fields but this doesn't copy exactly.</p>
  
  <pre><code>foreach (KeyValuePair&lt;string, AcroFields.Item&gt; kvp in pdfFormFields.Fields)
  {
      var s = pdfFormFields.GetFieldPositions("Date");
  
      PdfArray r = kvp.Value.GetWidget(0).GetAsArray(PdfName.RECT);
      var name = kvp.Value.GetWidget(0).GetAsArray(PdfName.NAME);
      Rectangle rr = new Rectangle(r.GetAsNumber(0).FloatValue, r.GetAsNumber(1).FloatValue, r.GetAsNumber(2).FloatValue, r.GetAsNumber(3).FloatValue);
      TextField field = new TextField(pdfStamper.Writer, rr, kvp.Value.GetWidget(0).Get(PdfName.T).ToString());
  
      if (kvp.Value.GetWidget(0).Get(PdfName.V) != null)
          field.Text = kvp.Value.GetWidget(0).Get(PdfName.V).ToString();
      // add the field here, the second param is the page you want it on
      pdfStamper.AddAnnotation(field.GetTextField(), filesByCategory[i].PageOfInsert + pageNum);
  
      fields.SetField(kvp.Key, kvp.Value.ToString());
  }
  </code></pre>
  
  <p>Is there a better way to do this? I've tried PdfCopy that looses bookmarks on the source document. </p>