Calculate PDF Form Prices from Multiple Selections in Adobe Acrobat
Question details
Calculate a PDF form price from package, sales category, and company-size selections without a large set of nested conditions.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form uses three selection fields to determine a price from a pricing table.
- Observed behavior
- The PRICE field should display the value matching the selected combination, with pricing data maintained separately from the calculation script.
Open the form in Adobe Acrobat and identify the exact field names and export values for the three selections and the PRICE field. Prepare a pricing table with one row per selection combination.
Look up prices from a text file attached to the PDF
Use an attached CSV pricing table and a custom calculation script to keep pricing combinations out of nested conditionals.
The example assumes selection fields named PACKAGE, SALES_CATEGORY, and COMPANY_SIZE, plus a calculated field named PRICE. Replace those names with the actual form field names.
The simple parser below expects comma-separated values without commas or line breaks inside fields. Selection values must match the table exactly, and prices must be numbers without currency symbols or thousands separators.
In a text editor, create a UTF-8 file named pricing.csv with a header and one row per combination. For example: package,sales_category,company_size,price Basic,Retail,Small,100 Basic,Retail,Large,150 Premium,Wholesale,Small,200
Open the PDF in Acrobat, open the Attachments panel, and use Add Attachment to attach pricing.csv. Keep the attachment name consistent with the script.
Open Prepare a Form, double-click PRICE, and select Calculate > Custom calculation script > Edit. Enter: var price = ""; try { var pkg = String(this.getField("PACKAGE").value); var category = String(this.getField("SALES_CATEGORY").value); var size = String(this.getField("COMPANY_SIZE").value); var text = util.stringFromStream(this.getDataObjectContents("pricing.csv"), "utf-8"); var rows = text.split(/\r\n|\n|\r/); for (var i = 1; i < rows.length; i++) { var cells = rows[i].split(","); if (cells.length === 4 && cells[0] === pkg && cells[1] === category && cells[2] === size && cells[3] !== "" && !isNaN(Number(cells[3]))) { price = Number(cells[3]); break; } } } catch (e) { console.println("Price lookup error: " + e); } event.value = price;
Save the PDF, then change each selection in the form and check that PRICE displays the matching table value. Test an unmatched combination as well; the example leaves PRICE blank when no matching row is found.

Work with PDF forms and pricing tables in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for working with PDFs and spreadsheets. Its Microsoft Office format compatibility makes moving existing pricing tables easier. The Acrobat-specific JavaScript lookup still requires a compatible PDF viewer.

Frequently Asked Questions
Why is the PRICE field blank after I select options?
Check that pricing.csv is attached under that exact name and that the script's field names match those in Prepare a Form. The selected export values must also match a complete CSV row exactly.
How do I update a price without editing the JavaScript?
Edit the relevant row in pricing.csv, then use Acrobat's Attachments panel to replace the embedded file with the updated version. Save the PDF and test the affected selections.
Can the pricing table contain commas in field values?
Not with the simple parser shown here: it splits each row at every comma. Use values without commas or implement a CSV parser that handles quoted fields.
Will the calculation work in every PDF viewer?
No. The lookup uses Acrobat JavaScript and its DataObjects API, which other PDF viewers may not support. Test the form in the Acrobat or Reader environment where it will be used.




