title: PdfTextFormField - 2 synchron Fields - How to fill in an initial value? - iText 7.1.0 for Java
body: <p>At the moment I'm writing a couple of evaluatuation programs with iText.</p>
  
  <p>I have an issue with 2 fields which should always have the same value (2 represantations of 1 field).</p>
  
  <p>In the final version these fields are on different pages at an arbitrary
  position.</p>
  
  <p>Setting the value with field.SetValue gives an error. Setting the value with
  widget1.setContents does nothing.</p>
  
  <p>Has someone an idea how to solve this problem?</p>
  
  <p>Thanks, Dirk</p>
  
  <pre><code>import java.awt.Desktop;
  import java.io.File;
  import java.io.IOException;
  
  import com.itextpdf.forms.PdfAcroForm;
  import com.itextpdf.forms.fields.PdfFormField;
  import com.itextpdf.forms.fields.PdfTextFormField;
  import com.itextpdf.kernel.geom.Rectangle;
  import com.itextpdf.kernel.pdf.PdfDocument;
  import com.itextpdf.kernel.pdf.PdfPage;
  import com.itextpdf.kernel.pdf.PdfWriter;
  import com.itextpdf.kernel.pdf.annot.PdfWidgetAnnotation;
  
  public class problem2 {
      public static void main(String[] args) throws IOException {
          String fnPdf = "results/problem2.pdf";
          PdfWriter writer = new PdfWriter(fnPdf);
          PdfDocument pdf = new PdfDocument(writer);
          PdfPage page = pdf.addNewPage();
          PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
          PdfTextFormField field = PdfFormField.createText(pdf);
          field.setFieldName("fName");
          // field.setValue("test"); // produces an error
          Rectangle rect1 = new Rectangle(40, 200, 150, 20);
          PdfWidgetAnnotation widget1 = new PdfWidgetAnnotation(rect1);
          widget1.setContents("test"); // no error but does'nt work
          page.addAnnotation(widget1);
          Rectangle rect2 = new Rectangle(240, 200, 150, 20);
          PdfWidgetAnnotation widget2 = new PdfWidgetAnnotation(rect2);
          widget2.setContents("test"); // no error but does'nt work
          page.addAnnotation(widget2);
          form.addField(field, page);
          field.addKid(widget1);
          field.addKid(widget2);
          pdf.close();
          Desktop.getDesktop().open(new File(fnPdf));
      }
  }
  </code></pre>