2

How can I get from which page is the field coming from?

PdfReader reader = new PdfReader(path);
AcroFields fields = reader.getAcroFields();
Set<String> fieldNames = fields.getFields.keySet();
for(String fieldName : fieldNames)
{
     String fieldValue = fields.getField(fieldName);
    //get page number for this field
}
Andrei Mihuț
  • 47
  • 1
  • 8

1 Answers1

3

You need the getFieldPositions() method. One field can correspond with more than one widget annotation. For instance, a field with name fieldName can be visualized on different pages, hence the method returns a List.

So if you want to get the page of the first (or only) item, you need:

int page = form.getFieldPositions(name).get(0).page;

By the way: the coordinates can be found like this:

Rectangle rectangle = form.getFieldPositions(name).get(0).position;
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165