To get PDF interactive form fields location information (including signature fields) such as dimension and page number, you will need to access the widget which is the visual representation of the field on the page.

When using Qoppa’s PDF components (jPDFViewer, jPDFNotes, jPDFEditor), you can get information from the editing component.

// get Acroform
AcroForm form = m_NotesBean.getDocument().getAcroForm();
 
// loop through the fields
Vector fieldList = form.getFieldList();
for(int count= 0; count < fieldList.size(); count++)
{
   // get current field
   FormField currentField = fieldList.get(count);
   System.out.println("Field Name " + currentField.getFieldName());
   // get the widgets for this field
   Vector widgets = currentField.getWidgets();
   if(widgets != null)
   {
     // get the first widget (usually the only one)
     Widget widget = (Widget) widgets.get(0);
     System.out.println("Widget Rectangle Location " + widget.getRectangle());
     AnnotationComponent component = (AnnotationComponent) widget.getComponent();
     if(component != null)
     {
         System.out.println("Component Located on Page Number " +  (component.getPageIndex() + 1));
     }
  }
}

A field is usually associated with one widget but it could also be associated with multiple widgets. This happens in the the case of what is known as “cloned fields” for instance, where the field’s value is synchronized among 2 or more widgets.

Here is the sample console output for this program:

Field Name EmailSubmitButton1[0]
Widget Rectangle Location java.awt.geom.Rectangle2D$Double[x=494.15000000000003,y=18.0,w=98.99999999999994,h=17.008000000000038]
Component Located on Page Number 1
Field Name TextSingleLine[0]
Widget Rectangle Location java.awt.geom.Rectangle2D$Double[x=208.701,y=29.835000000000036,w=76.46400000000003,h=21.33000000000004]
Component Located on Page Number 1

When using Qoppa’s PDF library jPDFProcess, there are no editing component for the annotations and widgets. You will need to loop through all the pages, through all the annotations contained in each page to find a matching one.

// Load the document
PDFDocument pdfDoc = new PDFDocument ("C:\\temp\\input.pdf", null);
 
if(pdfDoc.getAcroForm() != null)
{
 // get fields
 Vector<FormField> fields= pdfDoc.getAcroForm().getFields();
 
 if(fields != null)
 {
   for(int count = 0; count < fields.size(); count++)
   {
	// get current field 
	FormField currentField = fields.get(count);
	// get first widget for the field (usually only one)
	Widget widget = currentField.getWidgets().get(0);
	// loop through all pages in the PDF
	for(int i=0; i<pdfDoc.getPageCount(); i++)
	{
	    // get current page
            PDFPage currentPage = pdfDoc.getPage(i);
            // get annotations for current page
	    Vector<Annotation> annots = currentPage.getAnnotations();
            // loop through all annotations
	    for(int j=0; j<annots.size(); j++)
	    {
                if(annots.get(j) == widget)
		{
                     System.out.println("Field Name " + currentField.getFieldName());
                     System.out.println("Widget Rectangle Location " + widget.getRectangle());
                     System.out.println("Located on page " + (i +1));
		}
	    }
	 }
      }
   }
 }

Here is a sample output for this program:

Field Name Signature1
Widget Rectangle Location java.awt.geom.Rectangle2D$Double[x=188.67,y=43.960000000000036,w=196.10999999999999,h=68.96999999999991]
Located on page 1