Calculate an Invoice Discount Conditionally in Adobe Acrobat
Question details
Calculate an invoice field from the subtotal and discount only when a discount is entered.

- 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.
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.
Add a conditional calculation script to DiscTotal
Use a custom calculation script to leave DiscTotal blank when DiscValue is empty or zero.
Open the invoice in Adobe Acrobat and select All tools > Prepare a form.
Double-click the DiscTotal field and select the Calculate tab in its properties.
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 = "";
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.

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.

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.




