How to Use Calculation Scripts with Spawned PDF Form Templates
Question details
The user needs to correctly apply calculation scripts to dynamic PDF forms that spawn copies of template pages with unique field-name prefixes.

- Product
- Adobe Acrobat / PDF Editors
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where spawned template pages generate unique field-name prefixes that calculation scripts must recognize.
- Observed behavior
- Calculation scripts fail to work on spawned pages because the field names are automatically prefixed, requiring a dynamic method to identify the correct field instance.
Ensure you have basic familiarity with JavaScript for PDF forms and access to the document-level script editor in your PDF application.
Create a Document-Level Function to Extract Prefixes Dynamically
Use a custom JavaScript function at the document level to identify and return the prefix of spawned page fields at runtime.
When a PDF form spawns a template page, it automatically adds a prefix to the field names to keep them unique. To make calculations work on these new pages, your script must dynamically identify this prefix.
Instead of hardcoding field names, you can build a reusable document-level JavaScript function to calculate the current prefix on the fly.
Navigate to the JavaScript tools in your PDF editor and open the Document JavaScripts dialog box.
Create a new document-level function. Write a script that reads the event's target field name, splits the string at the periods (.), and isolates the prefix specific to the spawned page.
In your template page's calculation scripts, call the newly created document-level function to retrieve the current spawned-instance prefix.
Combine the returned prefix with the base field name using the getField() method so the calculation targets the correct instance of the spawned field.

Edit and Manage PDF Forms Easily with WPS Office
While advanced JavaScript for spawned templates requires specialized scripting, WPS PDF provides a comprehensive and user-friendly interface for creating, editing, and managing standard PDF forms without complex coding.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available form fields and editing tools.
- 3. Edit Form Properties: Double-click any form field to open its properties, where you can set standard calculation formulas, format rules, and actions.
- 4. Save and Export: Once your form is configured, save the document to ensure all interactive elements are preserved.

Frequently Asked Questions
Why do spawned PDF templates get different field names?
When a template page is spawned, the PDF application automatically adds a prefix to all field names on that new page. This ensures that each field remains unique across the document and prevents data from mirroring across multiple spawned pages.
What is a document-level script in a PDF?
A document-level script is JavaScript code that is embedded directly into the PDF document itself, rather than attached to a specific button or field. These scripts load when the document opens and can be accessed globally by any form field within the file.
How do I target a specific field on a spawned page?
You must construct the exact field name by combining the dynamically generated prefix of the spawned page with the original base name of the field, and then use the getField() JavaScript method to target it.
Can I use global variables instead of a document-level function?
It is highly recommended to use a document-level function rather than a global variable for this task. The function can be invoked precisely when a calculation needs the current prefix, ensuring the correct context is always evaluated.




