Access a PDF Field Label Bounding Box in Acrobat JavaScript
Question details
Determine whether Acrobat JavaScript can access the label object or bounding box associated with a PDF form field.

- Product
- Adobe Acrobat JavaScript
- Device & OS
- not provided
- Scenario
- A user wants to identify the text label and its position for a PDF form field using Acrobat JavaScript.
- Observed behavior
- The desired result is access to the label or its coordinates, separate from the form field's own bounding box.
Check whether the PDF is a standard Acrobat form or an XFA form created with LiveCycle Designer. For a standard form, identify the field name and page containing the visible label before inspecting coordinates.
Inspect the field and locate its label as page text
Use this approach for standard Acrobat forms, where visible labels are usually separate page content rather than field objects.
A field's rectangle describes the field widget, not the visible label. A field may also have a tooltip, but that text is not necessarily the label printed on the page.
Acrobat JavaScript can inspect extracted page words and their quadrilaterals. You must determine which words form the label; the API does not automatically associate them with the field.
Open the PDF in Acrobat, choose Prepare a Form, and select the field to check its name in the field properties.
Open the JavaScript console in Acrobat and evaluate this.getField("FieldName").rect, replacing FieldName with the actual field name. The returned rectangle is for the field, not its label.
In the console, use this.getPageNumWords(pageIndex) and this.getPageNthWord(pageIndex, wordIndex) to find the label words, then use this.getPageNthWordQuads(pageIndex, wordIndex) to inspect their coordinates. Page and word indexes start at zero.
To change the visible text rather than just inspect it, use Acrobat's Edit a PDF tool to select the label as page content, if the PDF permits editing.

Inspect a field caption in a LiveCycle Designer form
Use this approach when the form is an XFA form authored in LiveCycle Designer rather than a standard Acrobat form.
Edit PDF Content and Work with Office Files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Microsoft Office files. It can make moving between common document formats straightforward, but it does not provide a fix for Acrobat JavaScript's field-label API limitations.

Frequently Asked Questions
Does the field's rect property include its label?
No. In Acrobat JavaScript, this.getField("FieldName").rect returns the field widget's rectangle. A visible label in a standard PDF is usually separate page content.
Is a field tooltip the same as its visible label?
Not necessarily. A tooltip is field metadata, while the visible label may be independent text printed on the page.
How can I find the coordinates of a label in a standard PDF?
Use getPageNthWord to identify the label's extracted words and getPageNthWordQuads to inspect each word's coordinates. You must determine which words belong to the label.
What if Acrobat cannot extract the label text?
The label may be an image or otherwise unavailable as extractable text. Inspect the page visually and consider OCR if the label is part of a scan.
Do LiveCycle Designer forms handle labels differently?
Yes. XFA forms created in LiveCycle Designer can have captions associated with fields in the Designer form model. That differs from labels that are independent page content in standard Acrobat forms.




