Other PDF Issues

How to Search a PDF for Two Words Starting with Specific Letters

Camila MilosovichCamila Milosovich Nov 2, 2026 868 views

Question details

The user needs to find two consecutive words in a PDF that each begin with specific known letters.

How to Search a PDF for Two Words Starting with Specific Letters
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Locating specific word patterns or obscured terms in a large PDF document using programmatic searching.
Observed behavior
The standard search tool does not support regex, requiring a JavaScript and regular expression workaround to find the targeted letter patterns.
Before you start

Ensure you are using a PDF editor that supports JavaScript execution (like Adobe Acrobat Pro) and verify that your document contains searchable text rather than flat images.

Solution 1Recommended

Use Acrobat JavaScript and Regular Expressions

Execute a custom script that loops through every page and word in the PDF, applying a regular expression to find matching starting letters.

Because standard PDF search functions do not support complex regular expressions out of the box, you must use a scripting approach. By utilizing the Acrobat JavaScript API, you can programmatically extract text from the document word by word and test it against your specific criteria.

1
Open the JavaScript Debugger

Launch your advanced PDF editor (e.g., Acrobat Pro) and open the JavaScript Debugger console from the Tools panel.

2
Iterate through pages

Write a 'for' loop that uses 'this.numPages' to iterate through every single page in your open PDF document.

3
Iterate through words

Inside the page loop, create a nested loop using 'this.getPageNumWords(pageNum)' to scan every individual word on the current page.

4
Extract and test words

Use 'this.getPageNthWord(pageNum, wordNum)' to extract consecutive words. Apply a JavaScript regular expression (like /^C.* D.*/i) to check if the extracted word pair matches your desired starting letters.

5
Output the results

Use 'console.println()' to print the page number and matching words to the debugger console for easy reference.

Use Acrobat JavaScript and Regular Expressions
Scripting Flexibility: Combining getPageNthWord with regular expressions allows you to pinpoint any custom text pattern, no matter how complex the document is.
Advanced PDF Search Solution

Easily Search and Edit PDFs with WPS Office

While custom scripting is required for complex regex searches, WPS Office offers a comprehensive PDF toolkit with advanced built-in search functions, making it incredibly simple to find, edit, and manage your PDF documents without writing a single line of code.

  1. 1. Install WPS Office: Download and install the free WPS Office suite, then open your target PDF document.
  2. 2. Access the Search Tool: Press the Ctrl + F shortcut on your keyboard to instantly bring up the document search bar.
  3. 3. Enter Your Search Term: Type the specific letters, words, or phrases you are looking for into the search field.
  4. 4. Navigate Results: Click the next or previous arrow icons to quickly jump between all matching text occurrences in the document.
Instantly search for specific phrases, words, or character combinations across your entire PDF.Fully compatible with standard PDF formats and Microsoft Office files.Includes powerful built-in OCR to ensure text in scanned PDFs remains searchable.User-friendly interface for seamless reading, editing, and document management.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use regular expressions in standard PDF reader search bars?

Standard PDF readers typically only support exact text or basic whole-word searches. Regular expression (regex) searches generally require advanced tools with JavaScript capabilities or specialized third-party PDF plugins.

Why is the getPageNthWord script failing to find my text?

This commonly occurs if the PDF is a scanned image without a hidden text layer, or if it uses custom font encoding. You may need to run Optical Character Recognition (OCR) on the document to make the text readable by scripts.

Is it possible to automatically highlight the words my script finds?

Yes. Once your JavaScript identifies the matching words, you can use the 'getPageNthWordQuads' method to find the text's exact coordinates and then generate a highlight annotation object over that specific area.

Do I need to be a programmer to search PDFs?

No. While complex pattern matching (like searching for C*** D***) might require a script in some software, most standard searches can be done easily using the built-in Ctrl+F search feature in tools like WPS Office or standard PDF readers.