PDF Forms Calculate


This post discusses creating fillable PDF forms with Adobe Acrobat Pro 9. You can ask users to fill in some text boxes and then have another text box be the result of some calculation. Have a look at a previous post called PDF Forms with Acrobat Pro 9.

In this first example we are going to have a text box called “SalaryDesired” that accepts a number. Another text box will perform a calculation based on that number. We will simply double it. Below is the JavaScript code we can use in the Custom calculation script in the Calculate tab of the Properties of the control receiving the results of the calculation.

var dbl = this.getField("SalaryDesired");
event.value = dbl.value * 2;

From the above code you can see that we store the value in the text box SalaryDesired into a variable called dbl. Next we multiply dbl by 2 and put that value into the text box that contains this JavaScript code.

Custom Calculations – Income * TaxRate

Another more practical example would be to calculate the taxes based on an Income text box and a TaxRate text box and put the result of the product into a text box called Taxes. Also, you do not want the user to enter any values into the Taxes box. It is just for display. We can make it read-only by clicking the Read Only check box in the General tab of the properties..

What JavaScript code could you use? I ask this because the interface that does the work for me, does not seem to be working. I’m unable to select the two text boxes that I want to multiply together. I will use JavaScript as shown below.

var inc = this.getField("Income");
var tx = this.getField("TaxRate");
event.value = inc.value * tx.value;

JavaScript is a powerful language and there is much more to it that writing a few scripts. Check out the Math.round() function for example. It rounds up or down to the nearest integer and might come in handy.