How to Duplicate Selected PDF Pages Using Acrobat JavaScript
Question details
The user wants to duplicate specific pages within a PDF document using Adobe Acrobat's JavaScript capabilities via the Action Wizard.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Using the Acrobat Action Wizard to automate the duplication of selected pages across one or multiple PDF documents.
- Observed behavior
- Requires a custom JavaScript code snippet to loop through the document and insert copies of specific pages based on zero-based page indexing.
Always make a backup copy of your original PDF files before running any automated JavaScript actions, as incorrect page index modifications can duplicate pages in the wrong locations or overwrite document structures.
Use Acrobat JavaScript to Duplicate PDF Pages
Apply a custom JavaScript snippet in Adobe Acrobat's Action Wizard to automatically duplicate pages within the same document.
Adobe Acrobat allows you to use JavaScript to manipulate PDF pages dynamically. When duplicating pages, you use the 'insertPages' method to insert a copy of a page from the current document into a newly specified location.
When modifying page locations, loop backwards through the document pages. This prevents the page index from shifting forward as new pages are inserted, which can cause the script to target the wrong pages.
In Adobe Acrobat, go to the 'Tools' menu and select 'Action Wizard'.
Click 'New Action' to create a new sequence, or edit an existing one. From the 'More Tools' section on the left, add the 'Execute JavaScript' tool to your action steps.
Click to open the JavaScript editor and enter your duplication script. For example: `for (var p = this.numPages - 1; p >= 2; p--) { this.insertPages(p, this.path, p, p); }`
Modify the loop parameters (such as `p >= 2`) and the `insertPages` arguments to target the specific pages you want to duplicate. Remember that Acrobat page indexes are zero-based (page 1 is index 0).
Save the JavaScript action, then run it on your currently open PDF file or a batch of selected documents.

Use WPS Office to Easily Duplicate Pages Without Scripts
Skip the complex JavaScript coding. WPS Office includes a powerful, built-in PDF editor that allows you to easily duplicate, extract, or reorder selected PDF pages visually in just a few clicks.
- 1. Open the PDF in WPS Office: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
- 2. Access Page Management: Click on the 'Page' tab in the top navigation ribbon to enter the visual page management view.
- 3. Select Target Pages: Hold down the Ctrl key and click the thumbnails of the specific pages you want to duplicate.
- 4. Duplicate Pages Visually: Right-click the selected pages and choose 'Copy' (or extract them), then right-click your desired insertion point and select 'Paste'.

Frequently Asked Questions
What does zero-based indexing mean in Acrobat JavaScript?
Zero-based indexing means the first page of the PDF is referenced as page 0, the second page as page 1, and so forth. You must always subtract 1 from the actual physical page number when writing your JavaScript code to ensure you duplicate the correct page.
Can I duplicate multiple different pages at once using Acrobat JS?
Yes. You can use a loop (such as a 'for' loop) in your JavaScript code to iterate through a sequence of selected page indexes, calling the 'insertPages' method for each index.
Why did my Acrobat JavaScript insert the duplicated pages in the wrong order?
When duplicating multiple pages in a sequence, inserting a new page changes the overall page count and shifts subsequent indexes. It is strongly recommended to loop backwards (from the last page to the first) to prevent this index shifting.
Is there a way to duplicate a PDF page without using JavaScript?
Yes. Most standard PDF editors, including WPS PDF and Adobe Acrobat, allow you to duplicate pages manually. Simply open the Page Thumbnails panel, hold the Ctrl (or Option) key, and drag the page thumbnail to a new position to create a duplicate.




