How to Insert Blank Pages in PDF Using Acrobat JavaScript and Skip Specific Text
Question details
The user wants to write or modify an Adobe Acrobat JavaScript loop to insert blank pages after even-numbered pages, but skip pages that contain specific target words.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Automating PDF formatting and pagination workflows using custom document scripts.
- Observed behavior
- Needs to conditionally add blank pages based on page parity (even pages) and the presence of specific keywords to avoid altering critical pages.
Ensure you are using a desktop version of Adobe Acrobat Pro, as Acrobat Reader cannot execute page-modification JavaScript. Always create a backup of your original PDF document before running batch scripts.
Use Modulo Operator and Text Search in Acrobat JavaScript
Write a backward loop using the modulo operator to target even pages, and utilize text extraction methods to detect specific words before triggering the newPage function.
To avoid shifting the page indexes while inserting new pages, you must loop through the PDF document backwards (from the last page to the first page). Since Acrobat JavaScript uses a 0-based page index, visually even pages (e.g., Page 2, Page 4) actually have odd index numbers (1, 3, etc.).
In Adobe Acrobat Pro, go to Tools > Action Wizard or open the JavaScript Debugger Console (Ctrl+J or Cmd+J) to enter your custom script.
Write a loop that iterates backward through the document pages: `for (var i = this.numPages - 1; i >= 0; i--)`. This ensures that inserting a new page does not affect the index of the remaining pages you need to process.
Inside the loop, use the modulo operator to check if the visual page number is even. Because the index is 0-based, use `if (i % 2 !== 0)` to successfully target visually even pages.
Add an inner loop using `this.getPageNumWords(i)` to count words, and `this.getPageNthWord(i, j)` to extract and check each word against your target exclusion words. Set a boolean flag (e.g., `skipPage = true`) if the word is found.
Finally, add an `if (!skipPage)` condition. If the target word was not found on the even page, execute `this.newPage(i + 1);` to insert a blank page immediately after the current even page.

Easily Manage and Insert PDF Pages Visually with WPS Office
If writing complex Acrobat JavaScript loops is too time-consuming, WPS PDF offers a highly intuitive visual interface allowing you to insert, extract, and organize PDF pages instantly without any programming knowledge.
- 1. Open Your PDF: Launch WPS Office and open the PDF document you need to format.
- 2. Navigate to Page Tools: Click on the 'Page' tab located in the top navigation ribbon to reveal page management options.
- 3. Insert a Blank Page: Select the 'Insert Pages' button and choose 'Blank Page' from the dropdown menu.
- 4. Choose the Exact Location: In the pop-up dialog, select exactly where the blank page should be inserted (e.g., after specific even pages) and click 'OK' to apply.

Frequently Asked Questions
Why do I need to loop backwards when inserting pages via JavaScript?
When you insert a page into a PDF, all subsequent pages shift their index numbers up by one. Looping backwards ensures that the pages you have yet to process maintain their original index values during the script's execution.
How do I match an exact phrase instead of a single word using getPageNthWord?
Because the getPageNthWord method only extracts single words, you must capture multiple consecutive words, concatenate them into a string, and strip any punctuation to reliably match a specific multi-word phrase.
Does WPS Office support Adobe Acrobat custom JavaScript?
WPS Office focuses on providing visual, user-friendly tools for PDF editing and page management. While it does not process custom Adobe Acrobat JavaScript scripts directly, its built-in 'Page' menu handles most pagination tasks easily without code.




