How to Spawn Acrobat PDF Templates Based on Multiple Field Values
Question details
The user wants to use Acrobat JavaScript to dynamically spawn specific PDF page templates based on the combinations of a dropdown selection and a numeric text field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where specific pages need to be generated only after a user fills out multiple specific fields.
- Observed behavior
- Needs a JavaScript solution triggered by a single button to evaluate multiple fields and spawn the correct templates without creating duplicate pages.
Ensure that your required page templates are already created and marked as hidden in your PDF document, and note the exact names of the form fields you intend to evaluate.
Use JavaScript to Evaluate Fields and Spawn Templates
Retrieve values from the dropdown and text fields using valueAsString, then use logical AND in conditional statements to trigger the spawn action.
By centralizing the spawning script into a single button click at the end of the form, you can ensure all conditions are evaluated at once. This approach helps prevent duplicate pages from being generated if a user changes their field selections before finishing the form.
Locate the exact names of your dropdown field, numeric text field, and the names of the hidden page templates you want to spawn.
Insert a new button form field into your PDF that users will click to evaluate their choices and generate the required pages.
Open the button's properties, navigate to the Actions tab, select 'Run a JavaScript' from the dropdown, and click the Add button.
Write the script to read the fields, such as: var dropVal = this.getField('DropdownName').valueAsString; and var numVal = this.getField('TextName').valueAsString;.
Use an if/else if statement to evaluate combinations. For example: if (dropVal == 'Option1' && numVal == '2') { this.getTemplate('TemplateA').spawn(); }.

Edit and Manage PDF Pages with WPS Office
While advanced JavaScript template spawning requires complex coding in specific editors, WPS PDF provides an intuitive, code-free interface to manage PDF pages, insert pre-made templates, and fill out forms effortlessly.
- 1. Open your PDF: Launch WPS Office and open your PDF form or document in the WPS PDF editor.
- 2. Navigate to the Page section: Click on the 'Page' tab located in the top toolbar to access page management tools.
- 3. Insert or extract pages: Use the 'Insert' button to manually add pre-made template pages from other files, or 'Extract' to save specific pages as separate documents.
- 4. Fill and save: Fill out your necessary form fields directly in the reader, then save or export the finalized document.

Frequently Asked Questions
Can I use the logical OR operator instead of AND to spawn PDF templates?
Yes, you can use the logical OR (||) operator if you want the template to spawn when either the dropdown value or the numeric field matches your specified criteria.
Why are my PDF templates duplicating when users click the button multiple times?
This happens if the JavaScript does not check whether the page has already been spawned. You can prevent this by adding a boolean flag variable or renaming the spawned page so the script knows to skip it on subsequent clicks.
Do hidden PDF templates print if they are not spawned?
No, hidden page templates are specifically designed to be excluded from printing and standard viewing until they are explicitly spawned via a JavaScript action or manual unhiding.




