Thursday, September 17, 2015

Adding EXPIRY date into PDF using Javascript

Hi All,
Below are the code, which set the EXPIRY date in to a .pdf file.
//****************************************************//

//Declare the variable for storing Expiry date.
var expiryYear =2015;
var expiryMonth = 11; // Nov
var expiryDay = 20;

//Declare the variable for storing Current date.
var currentDate = util.printd("mm/dd/yyyy", new Date());

//Parse the date and store Day, Month, and Year into separate variable.
var currentDay = Number(String(currentDate).split("/")[1]);
var currentMonth = Number(String(currentDate).split("/")[0]);
var currentYear = Number(String(currentDate).split("/")[2]);

//alert the value for checking.
//app.alert("DD: "+currentDay+" MM: "+currentMonth +" YY: "+currentYear);

function checkExpiryDate()
{
     //showExpiryAlert();
    if(currentYear>expiryYear){
showExpiryAlert();
}
else if (currentMonth>expiryMonth && currentDay>expiryDay)
{
showExpiryAlert();
}
}

function showExpiryAlert(){

nRslt = app.alert ("Your subscription has been expired.", 1, 0, "ERROR");

if(nRslt == 1) {
event.target.closeDoc(true);
}
}

checkExpiryDate();

//End

No comments: