PDF Editing Issues

How to Calculate Contract Value in Adobe Acrobat PDF Forms Using JavaScript

John WilsonJohn Wilson Nov 5, 2026 869 views

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.

How to Calculate Contract Value in PDF Forms Using Custom JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the field properties

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'.

2
Navigate to the Calculate tab

Click on the 'Calculate' tab located at the top of the Text Field Properties dialog box.

3
Select custom calculation script

Choose the 'Custom calculation script' radio button and click the 'Edit' button to open the JavaScript Editor.

4
Enter the custom JavaScript code

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);`

5
Save and test the form

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.

Use Custom JavaScript in the PDF Field Calculation Properties
Field Name Consistency: Always double-check that the field names inside `this.getField('...')` exactly match the names of the fields in your PDF document, including spaces and capitalization.

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. 1. Open your PDF in WPS Office: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
  2. 2. Enter form editing mode: Navigate to the 'Form' tab on the top ribbon to access interactive form field tools.
  3. 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. 4. Save and share: Once your fields are configured, save the interactive PDF to share it seamlessly with your clients or colleagues.
Create interactive PDF forms with text fields, checkboxes, and drop-downs.Highly compatible with standard Adobe Acrobat PDF form elements.Lightweight, fast, and completely free to download.Edit text, images, and pages directly within your PDF documents.
microsoft office alternative - wps office

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.