How to PDF Form Calculations

PDF forms can perform automatic calculations — totaling line items on an invoice, computing tax amounts, calculating discounts, averaging scores, or deriving a BMI from height and weight fields. Calculated fields update in real time as users fill out the form, eliminating manual math and reducing input errors. SublimePDF supports calculated fields through JavaScript expressions attached to form field properties.

Follow the step-by-step instructions below, then use the free tool directly — no registration or download required.

Open Tool →

How to PDF Form Calculations — Step by Step

1

Create numeric input fields

Define input fields for values that feed into calculations. In your HTML template, use <input type='number' name='quantity' data-format='number'> and <input type='number' name='unitPrice' data-format='currency'>. The data-format attribute controls display formatting in the PDF.

2

Add a calculated field

Create a read-only field that displays the result: <input type='text' name='lineTotal' readonly data-calculation='quantity * unitPrice'>. The data-calculation attribute contains a JavaScript expression referencing other field names.

3

Define multi-field formulas

Reference any field by name in calculations: data-calculation='subtotal * (1 + taxRate) - discount'. Fields can reference other calculated fields, creating a chain: subtotal is calculated from line items, then total references subtotal.

4

Use aggregate functions

SublimePDF provides aggregate helpers for common operations: data-calculation='SUM(lineItem1, lineItem2, lineItem3)' and data-calculation='AVG(score1, score2, score3)'. These are cleaner than writing out long addition expressions.

5

Format calculation output

Apply data-format to calculated fields: 'currency' displays $1,250.00, 'percent' displays 12.5%, 'number' displays 1,250 with thousands separators. Formatting is applied after calculation, so the underlying value remains numeric.

Pro Tips

  • 💡 Set calculated fields to read-only (readonly attribute) to prevent users from overwriting computed values. The field updates automatically when input values change.
  • 💡 Test calculation chains by entering values in different orders — the form should produce correct results regardless of which field the user fills in first.
  • 💡 Use data-decimal-places='2' on currency fields to prevent floating-point display issues (e.g., $10.00000001 from JavaScript math).
  • 💡 For complex calculations that aggregate rows in a table, use SUM() with a field naming convention: name fields as 'row1_total', 'row2_total', etc., and calculate the grand total as SUM(row1_total, row2_total, row3_total).

Privacy & Security

All processing happens directly in your browser. Your files are never uploaded to any server — they remain on your device throughout the entire process. SublimePDF uses WebAssembly technology for fast, secure, client-side processing.

Works Everywhere

This tool works on any modern browser — Chrome, Firefox, Safari, or Edge — on desktop, tablet, or mobile. No software to install. PDF is an open ISO standard supported by all major platforms.

How to PDF Form Calculations — FAQ

Which PDF viewers support form calculations?
Adobe Acrobat Reader, Acrobat Pro, and Foxit Reader all support JavaScript-based form calculations. Browser-based PDF viewers and Apple Preview do not execute form calculations.
Can I use conditional logic in calculations?
Yes. Use ternary expressions: data-calculation='quantity > 100 ? unitPrice * 0.9 : unitPrice' applies a 10% discount for quantities over 100. For complex logic, define a custom calculation function in the 'formScripts' API parameter.
Why isn't my calculated field updating?
Common causes: the field isn't marked as calculated (missing data-calculation attribute), the referenced field names don't match exactly (case-sensitive), or the PDF viewer doesn't support JavaScript. Verify field names and test in Adobe Reader.
Can calculated fields reference fields on other pages?
Yes. PDF form calculations are document-wide — a field on page 5 can reference a field on page 1. Field names must be unique across the entire document.

Ready to get started?

Use SublimePDF's free tools right now.

Open Tool