PDF Editing Issues

Calculate an Invoice Discount Conditionally in Adobe Acrobat

Maira MehtabMaira Mehtab Nov 19, 2026 868 views

Question details

Calculate an invoice field from the subtotal and discount only when a discount is entered.

Calculate an Invoice Discount Conditionally in Adobe Acrobat
Product
Adobe Acrobat
Device & OS
not provided
Scenario
An invoice PDF has Subtotal, DiscValue, and DiscTotal form fields.
Observed behavior
DiscTotal should remain blank without a discount and show the calculated amount when a discount is entered.
Before you start

Open the invoice in a version of Adobe Acrobat that supports editing PDF forms. In Prepare a Form, confirm that the field names are exactly Subtotal, DiscValue, and DiscTotal.

Solution 1Recommended

Add a conditional calculation script to DiscTotal

Use a custom calculation script to leave DiscTotal blank when DiscValue is empty or zero.

1
Open the form editor

Open the invoice in Adobe Acrobat and select All tools > Prepare a form.

2
Open the field properties

Double-click the DiscTotal field and select the Calculate tab in its properties.

3
Enter the calculation

Select Custom calculation script, click Edit, and enter: var sub = Number(this.getField("Subtotal").value); var dv = Number(this.getField("DiscValue").value); if (dv) event.value = sub + dv; else event.value = "";

4
Save and test

Click OK, close the field properties, and save the PDF. Enter a subtotal, test a discount value, and then clear the discount to confirm that DiscTotal becomes blank.

Add a conditional calculation script to DiscTotal
Choose the right discount sign: The script adds DiscValue to Subtotal, so enter a reduction as a negative number. If discounts are entered as positive amounts, change sub + dv to sub - dv. A zero value is treated like no discount.
Free Microsoft Office alternative

Work with invoices and PDFs in WPS Office

WPS Office is a free, lightweight alternative for everyday document and PDF work, with a familiar interface and support for Microsoft Office formats to help you move existing files. Use Adobe Acrobat for the custom PDF calculation script described above.

Open and review invoice PDFs alongside other office documentsWork with Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface for everyday office tasksMove existing office files into a lightweight workspace
microsoft office alternative - wps office

Frequently Asked Questions

Where do I add the calculation script in Acrobat?

Open All tools > Prepare a form, double-click DiscTotal, and select Calculate > Custom calculation script > Edit.

Why is DiscTotal blank when I enter zero?

The condition if (dv) treats zero as false, so the script clears DiscTotal. It also clears the field when DiscValue is empty.

How do I subtract a positive discount amount?

In the DiscTotal custom calculation script, replace sub + dv with sub - dv. The discount value will then reduce the subtotal.

What if the field names in my PDF are different?

In Prepare a Form, check the names in each field's properties and replace Subtotal and DiscValue in the script with the exact names used in your PDF. Add the script to the field intended to display the result.