PDF Editing Issues

Create an Acrobat PDF Form That Calculates Feet and Fractional Inches

Huda QurayshiHuda Qurayshi Nov 18, 2026 868 views

Question details

Create a PDF form that accepts measurements in feet and fractional inches and compares them numerically.

Create an Acrobat PDF Form That Calculates Feet and Fractional Inches
Product
Adobe Acrobat PDF forms
Device & OS
not provided
Scenario
A form needs to accept measurements such as 35 inches, 35 1/4 inches, and 2 feet 11 1/4 inches, then return the smallest value.
Observed behavior
Acrobat does not provide a standard field number format for these measurement entries; custom validation and calculations are needed.
Before you start

Open the PDF in an Acrobat version that can edit form fields, and make sure JavaScript is enabled under Preferences > JavaScript. Decide on field names and an input convention; the example below uses Length1, Length2, and Smallest.

Solution 1Recommended

Validate measurements and calculate the smallest value with Acrobat JavaScript

Use this approach when users must enter fractional measurements and the form should return the smallest value in decimal inches.

The example accepts entries such as 35, 35 1/4, 1/8, and 2' 11 1/4. A trailing inch mark is optional. If feet are entered, an inch value must follow the apostrophe, such as 2' 0.

The calculation converts each entry to inches. It returns a decimal-inch value, not a formatted feet-and-fraction result.

1
Create the form fields

Open Tools > Prepare a Form and add text fields named Length1 and Length2 for the measurements and Smallest for the result. In each field's Properties > Format tab, choose None.

2
Add a conversion function

Open All tools > Use JavaScript > Document JavaScripts, or the equivalent Document JavaScripts command in your Acrobat version. Create a script and add: function parseMeasurement(s) { s = String(s).replace(/^\s+|\s+$/g, ''); if (!s) return null; var m = s.match(/^(?:(\d+)\s*'\s*)?(?:(\d+)(?:\s+(\d+)\/(\d+))?|(\d+)\/(\d+))\s*"?$/); if (!m) return NaN; var n = Number(m[3] || m[5] || 0), d = Number(m[4] || m[6] || 1); if (d === 0 || n >= d) return NaN; return Number(m[1] || 0) * 12 + Number(m[2] || 0) + n / d; }

3
Validate both input fields

For each input field, open Properties > Validate, select Run custom validation script, and enter: if (event.value !== '' && isNaN(parseMeasurement(event.value))) { app.alert('Enter inches such as 35 1/4 or feet and inches such as 2\' 11 1/4.'); event.rc = false; }

4
Calculate the minimum

Open Smallest Properties > Calculate, select Custom calculation script, and enter: var a = parseMeasurement(this.getField('Length1').valueAsString); var b = parseMeasurement(this.getField('Length2').valueAsString); if (a === null || b === null || isNaN(a) || isNaN(b)) event.value = ''; else event.value = Math.min(a, b);

5
Test the form

Close form editing, enter 35 1/4 in Length1 and 2' 11 1/8 in Length2, and confirm that Smallest displays 35.125. Try an invalid fraction such as 1/0 and check that the validation message appears.

Validate measurements and calculate the smallest value with Acrobat JavaScript
Viewer compatibility: PDF viewers differ in their support for Acrobat JavaScript. Test the completed form in the viewer your recipients will use; the calculation requires both input fields to contain valid measurements.
Free Microsoft Office alternative

Work with PDF and Office documents in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface for working with PDFs and Office files. Its format compatibility helps you move existing documents into your workflow; it does not replace the Acrobat JavaScript setup described above.

Open and work with PDF documents alongside other office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for moving between documents and spreadsheetsFree, lightweight alternative for everyday office work
microsoft office alternative - wps office

Frequently Asked Questions

What measurement formats does the example script accept?

It accepts decimal-free inch entries such as 35, 35 1/4, and 1/8, as well as feet and inches such as 2' 11 1/4. Use an apostrophe for feet and include an inch value after it. Fractions must have a nonzero denominator and a numerator smaller than the denominator.

Why is the smallest result shown as a decimal?

The calculation converts each measurement to numeric inches before comparing them. For example, 35 1/8 becomes 35.125. Displaying the result as a fraction requires an additional formatting script.

What happens if one measurement field is empty?

The example leaves Smallest blank until both Length1 and Length2 contain valid entries. You can change the custom calculation script if you want it to calculate from a single populated field.

Why does the form not calculate in a browser PDF viewer?

Some PDF viewers do not support Acrobat JavaScript. Open the form in a compatible viewer, such as Adobe Acrobat or Acrobat Reader, and check that JavaScript is enabled in Preferences > JavaScript.