How to Control the Order of Spawned PDF Form Pages
Question details
The user needs a reliable method to control the sequential order of dynamically spawned pages from PDF templates while ensuring that form data and page-specific values are preserved.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Managing dynamically generated PDF pages and forms via JavaScript.
- Observed behavior
- Dynamically added pages must be ordered properly, but doing so risks losing existing form data embedded in hidden templates depending on the bRename parameter settings.
Ensure you have saved a backup copy of your original PDF template and its current form data before executing JavaScript commands that delete and recreate pages.
Delete and Recreate Spawned Pages Systematically
The most practical approach to managing page order dynamically is to systematically delete all previously spawned pages and recreate them in the exact order required.
When spawning pages dynamically from templates using JavaScript, inserting them in a specific order can be technically challenging. By wiping the existing spawned pages first, you create a clean slate to generate the needed pages sequentially.
Determine which previously spawned pages currently exist within your PDF document.
Run a JavaScript function to systematically delete all these dynamically generated pages from the document.
Execute your page spawning script again to recreate the required pages in the exact sequence you want them to appear.

Store and Restore Values via JavaScript Array
Use this method if your bRename parameter is set to true to ensure form data is not lost when pages are deleted and recreated.
Manage PDF Forms and Pages Seamlessly with WPS Office
WPS Office provides advanced PDF editing tools that allow you to manage page order, edit templates, and handle interactive PDF forms effortlessly without relying entirely on complex JavaScript.
- 1. Open your PDF document: Launch WPS Office and open your PDF file using the built-in PDF Editor.
- 2. Navigate to the Page tab: Click on the 'Page' tab located in the top navigation menu.
- 3. Reorder pages visually: Use the drag-and-drop interface within the page thumbnail pane to easily reorder pages manually, or utilize the 'Delete' and 'Insert' buttons.
- 4. Manage form fields: Switch to the 'Form' tab to edit interactive form fields, check properties, and manage data efficiently.

Frequently Asked Questions
What does the bRename parameter do when spawning PDF pages?
The bRename parameter in Acrobat JavaScript determines whether the field names on the spawned page are renamed to be unique. If true, fields are renamed to prevent data from mirroring across identical fields, but you may need to manually save and restore specific values when recreating pages.
Why did my form data disappear after reordering spawned pages?
Form data can be lost if the spawned pages are deleted and recreated without first saving the data, especially if the bRename parameter is set to true. You must store the data in a JavaScript array before recreating the pages.
Can I reorder PDF pages manually instead of using JavaScript?
Yes, most PDF editors like WPS Office allow you to manually reorder pages by simply dragging and dropping them within the Page Thumbnails panel. This is often simpler and safer than using JavaScript for static documents.




