How to Add basic calculations to PDF form fields in Adobe's Acrobat Reader
Authored by: Support.com Tech Pro Team
1. Introduction
How to Add basic calculations to PDF form fields in Adobe's Acrobat Reader
2. Add basic calculations to PDF form fields
1: Predefined calculationsThe calculations like sum, product, average, minimum and maximum can be added using the predefined calculation. The below example shows how to use predefined calculations for two fields.
In the Prepare Form toolbar, select and add three text fields – Text1, Text2, and Text3. Text3 will be the calculated field.
Double-click the Text1 field to open its Properties. In the Format tab, Select Format Category as Number. Repeat this step for the remaining two text fields.
By default, the text fields are named as Text1, Text2, and so on. To change the name of the field, go to the General tab and enter the Name as Num1 or any other name you want, and click Close.
Double-click the Text3 field to open its Properties. In the Calculate tab, choose Value Is The, and in the drop-down list choose one of the following
To add Text1 and Text2, select Sum(+).
To multiply Text1 and Text2, select Product(x).
To calculate the average of Text1 and Text2, select Average.
To get the minimum of the numbers entered, select Minimum.
To get the maximum of the numbers entered, select Maximum.
Click Pick. In the Field Selection dialog, select Text1 and Text2, and click OK.
Click Close. When you enter numbers in Text1 and Text2 fields, Text3 displays the calculated value as per the chosen type of calculation in step3.
The predefined calculations are rather limited, for example, there is no division or subtraction.
2: Simplified field notation
The simplified field notation allows the creation of much more complex calculations. It uses a notation similar to how a calculation would normally be written, that is, using the regular math symbols, + (addition), - (subtraction), * (multiplication) and / (division). Field names are used as operands. To use the simplified field notation, do the following:
In the Prepare Form toolbar, select and add three text fields – Text1, Text2, and Text3. Text3 will be the calculated field.
Double-click the Text1 field to open its Properties. In the Format tab, Select Format Category as Number. Repeat this step for the remaining two text fields.
By default, the text fields are named as Text1, Text2, and so on. To change the name of the field, go to the General tab and enter the Name as Num1 or any other name you want, and click Close.
By default, the text fields are named as Text1, Text2, and so on. To change the name of the field, go to the General tab and enter the Name as Num1 or any other name you want, and click Close.
Double-click the Text3 field to open its Properties. In the Calculate tab, choose Simplified Field Notation, and click Edit.
In the JavaScript editor, enter the code to calculate. For example, to calculate the product of the sum of two numbers and subtraction of two numbers, type (Text1+Text2)*(Text1-Text2) and click OK.
Click Close.
3: Custom JavaScript calculations
Use custom JavaScript to create more complex math calculations. This option requires entering JavaScript and gives full access to all the fields in the PDF file, and the rich math features in the JavaScript language. It also requires use of the full Acrobat JavaScript syntax that makes the calculations longer. For example, the following code solves the same equation used in the simplified field notation example above.
In the Prepare Form toolbar, select and add three text fields – Text1, Text2, and Text3. Text3 will be the calculated field.
Double-click the Text1 field to open its Properties. In the Format tab, Select Format Category as Number. Repeat this step for the remaining two text fields.
By default, the text fields are named as Text1, Text2, and so on. To change the name of the field, go to the General tab and enter the Name as Num1 or any other name you want, and click Close.
Double-click the Text3 field to open its Properties. In the Calculate tab, choose Custom Calculation Script, and then click Edit.
In the JavaScript editor, enter your code for calculation. For example, to calculate the product of the sum of two numbers and subtraction of two numbers, type event.value=((this.getField("Text1").value+this.getField("Text2").value))*((this.getField("Text1").value-this.getField("Text2").value));