First part of your question:
Suppose that you have a
PdfAcroForm instance (
form), retrieved from a
PdfDocument in iText 7:
PdfDocument pdfDoc = new PdfDocument(new PdfReader(src)); PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
Then you can get the field position of the first widget that corresponds with a specific field name like this:
PdfArray position = form.getField(name).getWidgets().get(0).getRectangle();
Note that one field can correspond with multiple widgets. For instance, to get the second widget, you need:
PdfArray position = form.getField(name).getWidgets().get(1).getRectangle();
The position value will consist of the lower-left and upper-right x and y coordinates: [
If you want to know some information about the page, try this:
PdfPage page = form.getField(name).getWidgets().get(0).getPage();
Second part of your question
Fields correspond with widget annotations. If you know the page number of the widget annotation,
you could get the page dictionary and inspect the entries of the
You'll have to loop over the different annotations, inspecting each annotation's
Once you find a match, you need to crawl the content for the field that corresponds with the annotation.
That's more work than can be provided in a code sample on this site.
Click this link if you want to see how to answer this question in iText 5.