PDF Editing Issues

Set an If-Then-Else Calculation for Invoice Fields in Adobe Acrobat

Tauseeq MagsiTauseeq Magsi Nov 19, 2026 868 views

Question details

Set an invoice PDF field to 50 when the product of two other fields is greater than 1 and less than 50, and leave it blank when the first field is blank or zero.

Set an If-Then-Else Calculation for Invoice Fields in Adobe Acrobat
Product
Adobe Acrobat
Device & OS
not provided
Scenario
An invoice form uses fields A and B as inputs and field C as a calculated output.
Observed behavior
Field C should show 50 only for products strictly between 1 and 50 and should not retain an old value when the condition is not met.
Before you start

Open the invoice in Adobe Acrobat and confirm that the form fields are named A, B, and C. You need access to Acrobat's form-editing and custom calculation script tools.

Solution 1Recommended

Add a custom calculation script to field C

Use this script to calculate the product and clear field C whenever the specified condition is not met.

1
Open the form editor

Open the invoice PDF in Acrobat and select All tools > Prepare a form. Check the field names in the form editor.

2
Open field C's calculation settings

Double-click field C, select the Calculate tab, choose Custom calculation script, and click Edit.

3
Enter the script

Paste this script into the JavaScript editor and confirm it: var a = Number(this.getField("A").value); var b = Number(this.getField("B").value); var product = a * b; if (a !== 0 && isFinite(a) && isFinite(b) && product > 1 && product < 50) { event.value = 50; } else { event.value = ""; }

4
Test the form

Close the field properties, preview the form, and enter values in A and B. Test a product between 1 and 50, the boundary values 1 and 50, and a blank or zero value in A.

Add a custom calculation script to field C
Values outside the range: This script clears C for all products outside the specified range, including exactly 1 and 50. Change the else branch if the invoice requires a different result.
Free Microsoft Office alternative

Work with invoice documents in WPS Office

WPS Office is a free, lightweight alternative for working with office documents and PDFs. Its familiar interface and Microsoft Office format compatibility make it easy to move existing invoice files. Acrobat custom calculation scripts should still be configured and tested in Acrobat.

Open and work with invoice documents and PDFs in one suiteCompatible with Microsoft Word DOCX and Excel XLSX filesUse a familiar interface for a smoother transition from Microsoft OfficeGet free, lightweight tools for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

Where do I put the calculation script in Acrobat?

Select All tools > Prepare a form, double-click field C, and open Calculate > Custom calculation script > Edit.

Will field C show 50 when the product is exactly 1 or 50?

No. The conditions product > 1 and product < 50 exclude both boundary values.

Why does the script include an else branch?

The else branch assigns an empty string to event.value when the condition is not met, preventing field C from retaining a previous result.

What if my form fields have different names?

In the script, replace "A" and "B" in the getField calls with the exact names shown in Acrobat's form editor. Place the script in the output field's calculation settings.