PDF Editing Issues

Find PDF Text Coordinates and Add Annotations with Acrobat JavaScript

Maira MehtabMaira Mehtab Nov 19, 2026 869 views

Question details

Find the coordinates of PDF words or existing highlights and use them to place links, form fields, or annotations with JavaScript.

Find PDF Text Coordinates and Add Annotations with Acrobat 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.
Before you start

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.

Solution 1Recommended

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.

1
Open the JavaScript console

In Acrobat, open the PDF, then open the JavaScript Debugger console. Its location and availability depend on your Acrobat version.

2
Run the word search

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; } }

3
Check and save the result

Look for the yellow highlight on the first page, then use File > Save As to save the annotated PDF.

Find a word and highlight it with Acrobat JavaScript
Text and permissions matter: The script requires recognizable PDF text and permission to add comments. It highlights one word and does not export coordinates to a separate file.
Free Microsoft Office alternative

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.

Add PDF comments and highlights through a visual interfaceOpen and edit Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXUse a familiar interface for a smoother transition from Microsoft OfficeWork with documents in a lightweight office suite
microsoft office alternative - wps office

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.