How to Search a PDF for Two Words Starting with Specific Letters
Question details
The user needs to find two consecutive words in a PDF that each begin with specific known 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.
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.
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.
Launch your advanced PDF editor (e.g., Acrobat Pro) and open the JavaScript Debugger console from the Tools panel.
Write a 'for' loop that uses 'this.numPages' to iterate through every single page in your open PDF document.
Inside the page loop, create a nested loop using 'this.getPageNumWords(pageNum)' to scan every individual word on the current page.
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.
Use 'console.println()' to print the page number and matching words to the debugger console for easy reference.

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. Install WPS Office: Download and install the free WPS Office suite, then open your target PDF document.
- 2. Access the Search Tool: Press the Ctrl + F shortcut on your keyboard to instantly bring up the document search bar.
- 3. Enter Your Search Term: Type the specific letters, words, or phrases you are looking for into the search field.
- 4. Navigate Results: Click the next or previous arrow icons to quickly jump between all matching text occurrences in the document.

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.




