Thursday, February 24, 2022

Adobe PDF Script Calculate Age

 This is the script to calculate age in Adobe Acrobat Pro.  


This works but throws a internal error.


================================================

// Calculate Age 

// Ref: https://community.adobe.com/t5/acrobat-sdk-discussions/how-to-override-a-calculation-with-manual-entry-in-results-field/td-p/10856126


console.println("Calc Age Started");

var dobValue = getField("DOB").value;


if (dobValue!="") {


var dob = util.scand("mm/dd/yyyy", dobValue);


var today = new Date();


// compute years on full year only


var AgeCalulated = today.getFullYear() - dob.getFullYear();


// adjust for months before month of birth


if (today.getMonth() < dob.getMonth()) AgeCalulated = AgeCalulated - 1;


// adjust for today's month equal to dob's month and today's date before the date of birth


if ((today.getMonth() == dob.getMonth()) && (today.getDate() < dob.getDate())) AgeCalulated -= 1;


//event.value = AgeCalulated;

    console.println("Calc Age Proceess Start");

    getField("AGE").value=AgeCalulated;

    console.println("Calc Age Proceess Finished");


}

No comments:

Post a Comment