Automatically Stamp PDF Pages Near Matching Text in Adobe Acrobat
Question details
Place a PDF stamp at a fixed offset below each occurrence of a specified phrase across multiple pages.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF contains hundreds of pages, some with the instruction “Place your stamp here!”
- Observed behavior
- The user wants matching pages stamped automatically while pages without the phrase remain unchanged.
Confirm that the phrase is searchable text, not just an image; run OCR first if necessary. Test on a short copy of the PDF in Acrobat Pro with JavaScript enabled, and check whether any pages are rotated.
Use Acrobat JavaScript to stamp each matching phrase
Use this approach to scan unrotated pages and add a standard Approved stamp below every match.
The example matches four consecutive words, ignoring case and punctuation. It skips rotated pages and reports them for separate review. Stamp coordinates and sizes are measured in PDF points, where 72 points equal one inch.
Open the PDF in Acrobat Pro. Check Preferences > JavaScript to enable Acrobat JavaScript, then open the console with Ctrl+J on Windows or Command+J on macOS.
Paste the script below into the console, select it, and run the selection with Ctrl+Enter on Windows or Command+Enter on macOS: var target = ["place", "your", "stamp", "here"]; var found = 0; var skipped = []; for (var p = 0; p < this.numPages; p++) { if (this.getPageRotation(p) !== 0) { skipped.push(p + 1); continue; } var count = this.getPageNumWords(p); for (var i = 0; i <= count - target.length; i++) { var match = true; for (var j = 0; j < target.length; j++) { var word = this.getPageNthWord(p, i + j, true); if (word.toLowerCase().replace(/[^a-z0-9]/g, "") !== target[j]) { match = false; break; } } if (!match) continue; var quads = this.getPageNthWordQuads(p, i); if (!quads || !quads.length) continue; var x = quads[0][0], y = quads[0][1]; this.addAnnot({page: p, type: "Stamp", rect: [x, y - 72, x + 90, y - 36], AP: "Approved", contents: "Approved"}); found++; } } console.println("Stamps added: " + found); console.println("Rotated pages skipped: " + (skipped.length ? skipped.join(", ") : "none"));
Use the console report and Acrobat's page navigation to inspect matches, skipped pages, and stamps near page edges. Adjust the rect offsets and dimensions in the script for your layout; undo or reopen the test copy before rerunning to avoid duplicate stamps.
After checking the results, choose File > Save As and give the stamped PDF a new name. Handle any skipped rotated pages separately or adapt and test the script's coordinate transformation for rotation.

Review and annotate PDFs with WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Office format compatibility for a smoother migration. Its PDF tools are useful for reviewing and annotating documents, but they do not replace the Acrobat JavaScript automation described above.

Frequently Asked Questions
Will pages without the target phrase receive a stamp?
No. The script adds a stamp only when it finds the four target words in sequence on an unrotated page.
Can the script stamp more than one match on a page?
Yes. It continues scanning after each match, so every occurrence on an eligible page can receive a stamp.
What if the PDF is a scanned image?
Run OCR in Acrobat first, then use Find to verify that the phrase is searchable. The script relies on Acrobat's page-word APIs rather than detecting text in images.
How do I move or resize the stamp?
Change the four values in the script's rect array. The example uses a 90-by-36-point rectangle below the first matching word; test changes on a short copy before processing the full document.
Why were some pages skipped?
The example skips pages whose rotation is not zero and lists their page numbers in the JavaScript console. Review those pages separately or use a tested rotation-aware coordinate transformation.




