PDF Editing Issues

How to Calculate Total Cost from Quantity in an Acrobat PDF Form

Amos GikundaAmos Gikunda Oct 28, 2026 869 views

Question details

The user wants to automatically calculate a total price in a PDF form field by multiplying the values entered in the quantity and unit price fields.

How to Calculate Total Cost from Quantity in an Acrobat PDF Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating interactive PDF forms that require automatic calculations for invoices, order forms, or price quotes.
Observed behavior
The user needs to implement a custom script or calculation method to dynamically output the product of two form fields into a third total field.
Before you start

Ensure you are using a PDF editor that supports form field properties and custom JavaScript, and that your form already contains named fields for Quantity, Unit Price, and Total.

Solution 1Recommended

Use a Custom JavaScript Calculation Script

Add custom JavaScript code to the Total field to dynamically multiply the values of the Quantity and Unit Price fields.

This method gives you the most flexibility and is perfect if you need to perform more complex calculations in the future.

1
Open Form Properties

Right-click the 'Total' field in your PDF form and select 'Properties' from the context menu.

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 Script Option

Choose the 'Custom calculation script' option and click the 'Edit' button.

4
Enter the JavaScript Code

Input the following script: var quantity = Number(this.getField('Quantity').value); var price = Number(this.getField('UnitPrice').value); event.value = quantity * price;

5
Apply and Test

Click 'OK' to save the script, then close the properties window. Test the form by entering a quantity of 3 and a unit price of 4 to verify that the total automatically updates to 12.

Use a Custom JavaScript Calculation Script
Field Names Must Match: Ensure that 'Quantity' and 'UnitPrice' exactly match the actual names of the fields in your PDF form. JavaScript is case-sensitive.
Seamless PDF Management

Fill and Manage PDF Forms Easily with WPS Office

WPS Office features a powerful built-in PDF reader and editor that effortlessly handles interactive PDF forms, including those with advanced JavaScript calculations, making document processing fast and easy.

  1. 1. Open PDF in WPS Office: Launch WPS Office and open your interactive PDF document containing the form fields.
  2. 2. Fill the Form Fields: Click directly into the text fields, such as Quantity or Unit Price, and input your numerical values.
  3. 3. View Auto-Calculations: WPS PDF will seamlessly process the embedded calculation rules or JavaScript to automatically generate the correct Total Cost.
Seamlessly fill out interactive PDF forms with embedded auto-calculation scriptsFully compatible with standard Adobe Acrobat PDF formatsLightweight application that uses minimal system resourcesEasily view, edit, merge, and convert PDF documents in one place
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF form calculation not updating automatically?

This usually happens if the calculation order is incorrect or if JavaScript is disabled in your PDF viewer. Check your application settings to ensure JavaScript is enabled, and verify that the Total field is calculated after the Quantity and Unit Price fields.

Can I format the total field to show currency symbols?

Yes. In the Total field's properties, navigate to the 'Format' tab. Choose 'Number' or 'Special', and you can select a currency symbol and specify the number of decimal places you want to display.

Does the custom script work if the fields are left blank?

If fields are left blank, the script usually treats them as zero, resulting in a total of zero. To prevent this, you can add an 'if' statement in your JavaScript to only calculate the total when both fields have numerical values.