Calculate Mileage and Total Fields in an Acrobat PDF Form
Question details
Calculate the mileage for each row of a PDF log and add all row mileage values into a total field.

- 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.
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.
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.
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.
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);
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.
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.
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.

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.

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.




