How to Calculate Contract Value in Adobe Acrobat PDF Forms Using JavaScript
Question details
The user needs to calculate a total contract value in a PDF form by multiplying the floor area, price per square meter, and a minimum 52-week hire period, then display the result as a formatted currency range.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an automated PDF contract form that calculates specific values based on user input for area, price, and fixed constants like minimum weeks or delivery rates.
- Observed behavior
- The form needs to dynamically fetch input field values, perform multiple mathematical operations including multiplication by 52, and output a string with a formatted currency range.
Ensure your PDF editor supports custom JavaScript for form fields, and verify the exact names of your input fields (e.g., 'Floor Area', 'requirements 14') before writing the script, as field names are case-sensitive.
Use Custom JavaScript in the PDF Field Calculation Properties
Add a custom JavaScript calculation script to the target contract value field to fetch input variables, apply the 52-week multiplier, and format the output as a currency range.
A standard multiplication format under the calculate tab cannot mix basic variables with static numbers like a 52-week period and specific text strings. A custom JavaScript provides the flexibility required to fetch multiple fields, calculate two different requirement scenarios, and bind them into one text string with currency formatting.
In PDF form editing mode, right-click the target field where the total value should appear (e.g., 'Contract Value' or 'Requirements 15') and select 'Properties'.
Click on the 'Calculate' tab located at the top of the Text Field Properties dialog box.
Choose the 'Custom calculation script' radio button and click the 'Edit' button to open the JavaScript Editor.
Input the script to calculate both ranges: `var req1 = Number(this.getField('requirements 14').valueAsString);` `var req2 = Number(this.getField('requirements 25').valueAsString);` `var area = Number(this.getField('Floor Area').valueAsString);` `var c1 = area * req1 * 52;` `var c2 = area * req2 * 52;` `event.value = util.printf('£%,0.0f', c1) + ' - ' + util.printf('£%,0.0f', c2);`
Click 'OK' to save the script, close the properties window, exit form editing mode, and test the form by entering sample values into the required input fields.

Add Calculations for Delivery and Foundations Based on Floor Area
Apply a simpler version of the JavaScript calculation logic to additional fields that require flat-rate multipliers based purely on the Floor Area.
Create and Manage Automated PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to create interactive forms, add input fields, and easily manage document workflows without needing expensive software.
- 1. Open your PDF in WPS Office: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
- 2. Enter form editing mode: Navigate to the 'Form' tab on the top ribbon to access interactive form field tools.
- 3. Add or edit text fields: Insert a 'Text Field' and double-click it to open the properties panel, where you can define formatting and data requirements.
- 4. Save and share: Once your fields are configured, save the interactive PDF to share it seamlessly with your clients or colleagues.

Frequently Asked Questions
Why is my PDF JavaScript calculation not returning any value?
This usually happens if the field names in your script do not exactly match the actual field names in the PDF form, or if a typo exists in the script syntax. Ensure exact case matching in `this.getField('FieldName')`.
How do I format a JavaScript calculation result as currency in a PDF?
You can format the output directly in the script using `util.printf('£%,0.0f', value)`. This specific format command adds the pound sign, includes comma separators for thousands, and restricts the output to zero decimal places.
Can I perform different mathematical operations in one PDF form field?
Yes. By using custom calculation scripts, you can fetch variables from multiple input fields and perform complex combinations of addition, multiplication, division, and string concatenation within a single script.




