Find PDF Text Coordinates and Add Annotations with Acrobat JavaScript
Question details
Find the coordinates of PDF words or existing highlights and use them to place links, form fields, or annotations with JavaScript.

- Product
- Adobe Acrobat JavaScript
- Device & OS
- not provided
- Scenario
- A user wants to locate text or highlights in a PDF and use their positions to place interactive elements or comments.
- Observed behavior
- Word and annotation coordinates can be read as quadrilaterals and used directly or converted to rectangles, depending on the target object.
Open a text-based PDF in Acrobat and make sure the document permits the annotations or form changes you want to add. For a scanned PDF, run OCR first so Acrobat can recognize words.
Find a word and highlight it with Acrobat JavaScript
Use word quadrilaterals to locate an exact word and create a highlight at its position.
Acrobat numbers pages and words starting at zero. The example searches the first page for the first exact, case-insensitive match; change the page number and search term as needed.
In Acrobat, open the PDF, then open the JavaScript Debugger console. Its location and availability depend on your Acrobat version.
Enter and execute this script in the console: var p = 0; var target = 'example'; var count = this.getPageNumWords(p); for (var i = 0; i < count; i++) { if (this.getPageNthWord(p, i, true).toLowerCase() === target.toLowerCase()) { var q = this.getPageNthWordQuads(p, i); if (q && q.length) { this.addAnnot({page: p, type: 'Highlight', quads: q, strokeColor: color.yellow}); } break; } }
Look for the yellow highlight on the first page, then use File > Save As to save the annotated PDF.

Convert word quadrilaterals into a rectangle for a link or field
Use a bounding rectangle when the object you want to create requires a rectangle rather than quadrilaterals.
Read the coordinates of an existing highlight
Inspect an existing annotation's quadrilaterals when the starting point is a highlight rather than a word search.
Edit and Annotate PDFs with WPS Office
WPS Office is a free, lightweight alternative for everyday document and PDF work. Its familiar interface and Microsoft Office format support make it easy to move existing files into your workflow; it does not replace Acrobat's JavaScript coordinate APIs.

Frequently Asked Questions
Can Acrobat JavaScript get the coordinates of a PDF word?
Yes. Use getPageNthWordQuads(pageIndex, wordIndex) to retrieve the word's quadrilaterals. Use getPageNumWords and getPageNthWord to search through words on a page.
How do I use word coordinates to create a link?
Convert the word's quadrilaterals into a bounding rectangle in [minX, maxY, maxX, minY] order, then call this.addLink(pageIndex, rect) and configure its action.
Can I get coordinates from an existing highlight?
Yes. Use this.getAnnots({nPage: pageIndex}) to find page annotations, then inspect the quads property of a Highlight annotation.
Will this automatically export coordinates to a file?
No. getPageNthWordQuads returns coordinates to the script; exporting them requires additional code and an export method permitted by the Acrobat environment.
Why does the word search return no match?
The page may be an image without recognizable text, the search term may not match the extracted word, or the page index may be wrong. Run OCR on a scanned page and check the text and zero-based page index.




