قالب وردپرس درنا توس
Home / Tips and Tricks / How to create conditional formulas in Adobe Acrobat

How to create conditional formulas in Adobe Acrobat



Adobe Acrobat Pro logo
Adobe

There are several ways to create complex calculations in a clean, elegant PDF file. How to integrate conditional formulas into your next document.

Conditional formulas in Acrobat

We have previously covered the basics of automatic calculations in Adobe Acrobat. Conditional formulas let you go beyond the basics and create more complex formulas in a PDF.

RELATED: How to create PDF forms with calculations in Adobe Acrobat

If you use formulas in Excel or Google Sheets, you probably already know which conditional formulas. Also called logical formulas, they show a certain value or activate a calculation if a certain condition is met, for example if a number is negative or if a point is above a passing grade. Some of the most common conditional formulas in excel include the standard “IF”

; as well as “SUMIF” and COUNTIF. “There is also conditional formatting, where changes to the format are made if a cell meets a certain condition.

Using calculated fields, these formulas can also be applied to Adobe PDF files. You can display a number, text or run a calculation based on the results from another input box. You can also use them in conjunction with other calculated fields. Conditional formulas are useful for many types of PDF forms, such as:

  • Financial documents: For example, if the principle determines someone’s interest rate, a conditional formula can be used to show the corresponding price based on the amount they specify.
  • Tests and exams: You can make an assessment that automatically shows either “pass” or “fail” at the end based on the test taker’s total score.
  • sale: If you use this for transactions, you can create a box that recommends products depending on a potential buyer’s answers to specific questions.

Note that although calculated fields can only be done in Adobe Acrobat, the actual calculations will be displayed in all PDF readers.

Create simple conditional statements

Adobe Acrobat’s custom computed fields use javascript as the programming language. Fortunately, you do not need to know how to program in javascript to create a simple conditional field; you just need a basic pattern to follow.

In the following example, we use this simple company order form. This currently has seven fields: one for quantities of each of the five products, the total quantity and the total price.

Adobe Acrobat Simple Form

A conditional statement in Adobe javascript follows this basic syntax:

var variable name = this.getField("name of field").value;
if( variable name condition) event.value = true result
else event.value = false result

The first line defines the value that will be used for your conditional formula. In this case, we used “this.getField” to get the value of one of the other fields in the document. On the second line, we define the condition. Like excel, we specify the condition as greater than, less than or equal to a certain value.

Finally, we define the results. The real result is the value that will be displayed if the condition is met. On the next line, we use “other” to generate false result, which is the value that will be displayed if the condition is not met.

To implement this, we have created a calculated field called “Bulk Order”. To enter a custom calculated script, right-click on the selected field in Acrobat and select “Properties”. From here, go to “Calculate> Custom Calculation Script> Edit.”

Adobe Acrobat Custom Calculation

This field determines whether an order counts as bulk. The box shows “Yes” if the total amount is greater than 20 items and “No” if it is less than 20. Given these conditions, we have the formula:

var TQ = this.getField("Total Quantity").value;
if( TQ > 20) event.value = "Yes"
else event.value = "No"

In the image above you can see that we set the variable name to “TQ” and subtracted the value of TQ from the field “Total quantity.” Note that these fields are case sensitive. Then we set our condition, which is that the TQ must be greater than 20. If it meets this condition, it will show “Yes.” Otherwise, the “No” box generates

Adobe Acrobat Javascript

If we ordered a total of 11 lightning cables and 10 battery banks, for example, we would have a total of 21 items. It would then be considered a bulk order and generate the following results:

Adobe Acrobat Order Result

Several conditions

There are cases where you may want several conditions met instead of just one. Fortunately, there is a way to create a conditional field that generates values ​​based on multiple conditions.

Adobe Acrobat Multiple Terms

Let’s say that in your store, all orders that reach at least 20 products and have a total price of 150 are entitled to a discount of 10%. The final amount is displayed in a field called “Total with discount.” In that case, we must specify two variables and two conditions. We would have the following fields:

var Price = this.getField("Initial Price").value;
var TQ = this.getField("Total Quantity").value;
if( Price > 150 && TQ > 20 ) event.value = Price*0.9;
else event.value = Price;

As you can see, we defined two variables on two separate lines. You must also use the “&&” notation to combine the two different terms. Note that the final value is also a calculation that takes into account the discount.

Therefore, if we use the same sum as the example above, we generate the following results:

Adobe Acrobat Multiple Terms Results

Calculation Order

An important consideration you should make is the calculation procedure. Unlike Excel, which does calculations simultaneously, Acrobat relies on the user to determine which formulas come first.

To set the calculation order, go to the sidebar “Edit shape” and navigate to More> Set field calculation order. In the example above, since the formulas for Bulk Order and Total With Discount are both dependent on Total Quantity and Total Price, we want to make sure that TQ and TP are calculated first.

Adobe Acrobat Field Calculations

Be sure to review the calculation order before publishing the form. It is a good idea to try some sample entries on your form to make sure everything works correctly.




Source link