How to Extract PDF Text from Bounding Box Coordinates using Acrobat JavaScript
Question details
Developers need a way to target and extract specific text from defined geometric regions in a PDF, such as headers or footers, using bounding box coordinates.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Extracting text from specific X/Y coordinate areas on a PDF page via scripting instead of manual selection.
- Observed behavior
- Users require a reliable JavaScript method to loop through PDF pages, evaluate physical word positions, and extract only the words that fall within designated coordinate frames.
Ensure you have Adobe Acrobat Pro installed, as Acrobat Reader does not support document-level JavaScript execution for advanced text coordinate extraction.
Use Acrobat JavaScript API to Extract Text by Coordinates
Write a custom script using getPageNthWord and getPageNthWordQuads to evaluate text positions and extract words within specified bounding boxes.
The Acrobat JavaScript API provides methods to access page text and its precise physical location on the document canvas. By looping through each word on a page, retrieving its quad coordinates, and applying matrix transformations, you can filter text based on specific X and Y boundaries.
Launch Adobe Acrobat Pro, open your target PDF, and access the JavaScript Debugger console by pressing Ctrl+J (Windows) or Cmd+J (Mac).
Set up a script to iterate through the document pages using this.pageNum and get the total number of words on the target page using the this.getPageNumWords(p) method.
Create a loop that retrieves each word index with this.getPageNthWord(p, i, false) and gets its spatial coordinates using this.getPageNthWordQuads(p, i).
Apply a matrix transformation using (new Matrix2D).fromRotated(this,p) and invert it to normalize the coordinates so they map correctly to your expected grid.
Use an if statement to check if the transformed coordinates fall within your defined bounding box (e.g., if (Number(r[0])>300 && Number(r[1])<35)), and append the matching words to your output variable.

Easily Extract Text from Specific PDF Regions with WPS Office
If writing complex JavaScript coordinate code is too time-consuming, you can easily extract text from specific regions visually using WPS Office. The built-in PDF tools allow you to highlight areas, use OCR for image-based regions, and extract text without writing a single line of code.
- 1. Open your PDF: Launch WPS Office and open your target PDF document.
- 2. Select the Text Tool: Navigate to the 'Home' or 'Edit' tab in the top ribbon and choose the text selection tool.
- 3. Highlight the Bounding Box: Use your cursor to visually drag a bounding box around the specific area (like a header or footer) you want to extract text from.
- 4. Copy the Text: Right-click the highlighted text and select 'Copy' to immediately extract the content to your clipboard.
- 5. Use OCR for Scanned Pages: If the PDF is scanned and the text is not selectable, click the 'OCR' button in the toolbar, select the screen area, and let WPS Office automatically extract the text.

Frequently Asked Questions
What is the getPageNthWordQuads method in Acrobat JavaScript?
It is an Acrobat JavaScript API method that returns an array of quadrilateral coordinates for a specific word on a PDF page. This allows developers to determine the exact physical location and bounding box of text elements.
Why is my JavaScript text extraction script returning empty strings?
This usually happens if the X and Y coordinate thresholds in your script do not match the actual bounding box layout of the PDF, or if the document contains flattened images rather than actual embedded text.
Can I automate coordinate text extraction across multiple PDFs?
Yes, you can implement your coordinate-based script inside an Action Wizard sequence in Adobe Acrobat Pro to run a batch process, automatically extracting specific regions across multiple PDF files in a selected folder.




