PDF Editing Issues

How to Sum Only Positive Form Values in PDF with Acrobat Script

Maira MehtabMaira Mehtab Nov 10, 2026 868 views

Question details

The user needs to calculate a subtotal in a PDF form by summing only positive field values while ignoring any negative numbers.

How to Use a Custom PDF Script to Sum Only Positive Form Values
Product
PDF
Device & OS
not provided
Scenario
Calculating a taxable product subtotal on a PDF quote form where negative rebate values should not reduce the total sum.
Observed behavior
Standard built-in sum functions automatically include negative values, improperly reducing the total instead of treating them as zero.
Before you start

Ensure you are using a PDF editor that supports form field editing and custom JavaScript, such as Adobe Acrobat Pro. Take note of the exact field names you wish to include in your sum calculation.

Solution 1Recommended

Apply a Custom JavaScript Calculation to the Total Field

Use a custom calculation script that iterates through your specific target fields, converting them to numbers and adding them to the total only if they are greater than zero.

By default, built-in PDF calculation tools perform straight mathematical sums. To apply conditional logic (like ignoring negative values), you must use JavaScript.

1
Enter form editing mode

Open your PDF file in your advanced PDF editor and navigate to the 'Prepare Form' or 'Form Editing' tool area.

2
Access field properties

Right-click the text field where you want the final subtotal to appear and select 'Properties' from the context menu.

3
Enable custom calculations

Navigate to the 'Calculate' tab in the Properties window. Select the option for 'Custom calculation script' and click the 'Edit' button.

4
Input the script

In the JavaScript editor, paste the following code: var fieldsToAdd=["Text1","Text2","Text3"]; var total=0; for(var i=0;i<fieldsToAdd.length;i++){var v=Number(this.getField(fieldsToAdd[i]).valueAsString); if(v>0) total+=v;} event.value=total;

5
Update field names and save

Replace "Text1", "Text2", and "Text3" in the script with your actual form field names. Click 'OK' to save the script, then close the Properties window and test your form.

Apply a Custom JavaScript Calculation to the Total Field
Script Accuracy: Field names are case-sensitive. Ensure the names in your array exactly match the names of the form fields in your PDF.
Edit & Manage PDF Forms Easily

Handle PDF Forms and Documents with WPS PDF

WPS Office includes a powerful PDF editor that allows you to effortlessly view, fill, and manage PDF forms. With comprehensive document tools, you can handle complex office tasks efficiently.

  1. 1. Open WPS Office: Launch the WPS Office application and click on the 'PDF Edit' module from the home screen.
  2. 2. Load your document: Open your PDF form or document within the application to start viewing or editing.
  3. 3. Fill the form: Use the interactive PDF tools to fill out text fields, select checkboxes, or apply secure digital signatures.
  4. 4. Save and export: Once your form is completely filled and calculated, click 'Save' or export it directly as a flattened PDF file.
Easily view, fill, sign, and print PDF forms without hassleHighly compatible with Microsoft Office formats (Word, Excel, PPT) and standard PDFsLightweight software that runs smoothly on Windows, Mac, and LinuxBuilt-in robust tools to convert PDFs to editable Word or Excel files
microsoft office alternative - wps office

Frequently Asked Questions

Why does standard PDF sum calculation include negative values?

The built-in sum function in PDF editors simply adds all raw mathematical values from the selected fields. To conditionally ignore negative numbers, you must override this behavior with a custom JavaScript snippet.

How do I find the exact field names in my PDF form?

Enter the 'Prepare Form' or form editing mode in your PDF software. The internal field names will be displayed as labels over each text box. You must type these exact names into your script array.

Will this JavaScript calculation work in web browsers or mobile PDF viewers?

Many basic web browser PDF viewers and default mobile apps do not support executing custom JavaScript in forms. For best results, users should fill the form using a dedicated desktop PDF reader.