PDF Editing Issues

Calculate Mileage and Total Fields in an Acrobat PDF Form

Olivia MillerOlivia Miller Nov 18, 2026 869 views

Question details

Calculate the mileage for each row of a PDF log and add all row mileage values into a total field.

Calculate Mileage and Total Fields in an Acrobat PDF Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A mileage-log PDF form contains starting and ending odometer readings across 60 rows.
Observed behavior
Each mileage field should show the ending reading minus the starting reading, and the total field should sum all mileage entries.
Before you start

Open the PDF in a version of Adobe Acrobat that can edit form fields, and check the exact names of the start, end, mileage, and total fields in Prepare a Form. The example below assumes fields named Start1, End1, and Mileage1 through Start60, End60, and Mileage60.

Solution 1Recommended

Add custom calculation scripts to the mileage and total fields

Use Acrobat's form-field calculations to compute each row and the overall total automatically.

1
Open the form editor

In Acrobat, open the PDF and select All tools > Prepare a form. Check the field names in the form editor and rename them or adapt the scripts to match.

2
Calculate the first row

Double-click the Mileage1 field, open Properties > Calculate, select Custom calculation script, and click Edit. Enter: var start = this.getField('Start1').valueAsString; var end = this.getField('End1').valueAsString; event.value = (start === '' || end === '') ? '' : Number(end) - Number(start);

3
Adapt the script for each row

Open Properties > Calculate for each remaining mileage field. Copy the first script and change Start1 and End1 to the corresponding row names, such as Start2 and End2 for Mileage2, through row 60.

4
Add the total calculation

Double-click the total field, select Properties > Calculate > Custom calculation script, and click Edit. Enter: var total = 0; for (var i = 1; i <= 60; i++) { var f = this.getField('Mileage' + i); if (f && f.valueAsString !== '') { var n = Number(f.value); if (!isNaN(n)) total += n; } } event.value = total; Change 60 or the Mileage prefix if your form uses a different row count or naming pattern.

5
Set calculation order and test

In Prepare a form, open More > Set field calculation order and place the total field after all mileage fields. Save the PDF, enter sample readings in several rows, and confirm that each difference and the grand total update.

Add custom calculation scripts to the mileage and total fields
Check field names and numeric input: Field names in scripts must match the form exactly. Enter numeric odometer readings; the row script leaves mileage blank until both readings are entered.
Free Microsoft Office alternative

Track mileage in a WPS Spreadsheets workbook

For an alternative mileage log, use WPS Spreadsheets to calculate row differences and totals, then export a static PDF. WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for easy migration. It does not add Acrobat calculation scripts to the existing PDF form.

Calculate mileage differences and totals with spreadsheet formulas.Open and save Microsoft Excel XLSX files.Use a familiar spreadsheet interface for an easy transition.Export a completed mileage log as a static PDF.
microsoft office alternative - wps office

Frequently Asked Questions

Where do I add a calculation script in Acrobat?

Open All tools > Prepare a form, double-click the field, and choose Properties > Calculate > Custom calculation script > Edit.

Why is the total not updating after a row changes?

In Prepare a form, open More > Set field calculation order and move the total field after the mileage fields. Also check that the total script uses the exact mileage field names.

Can I use the same script for every mileage row?

Yes. Copy the row script into each mileage field, but change the start and end field names to match that row.

How do I change the script for a different number of rows?

In the total field's custom calculation script, replace 60 in the loop condition with the actual row count. Make sure the mileage field prefix and numbering also match the form.

Can I create these calculations in Acrobat Reader?

Reader can fill compatible forms, but adding or editing form-field calculation scripts requires a version of Acrobat with form-editing tools.