Login using the username and password you created for AcrobatUsers.com.
Note: This is not the same as your Adobe ID.
Benefits of Free Membership:
Find out what AcrobatUsers.com is all about
You don't have to be a member to look at any content on the site. Increase your expertise with our helpful tutorials, videos, forums, and sample PDFs.
Like what you see? Take the next step and become a member. Register now to get discounts, attend eSeminars, ask questions and more.
Get the most out of your membership. Post in the forums, create your profile, submit to the gallery, attend a user group meeting. Log In now.
Hello,
I use a script to print the print date + 1 day on a PDF document. This date appears only when the document is printed.
The script works but I get error messages that I cannot debug.
Here is the script:
/* Date Printed */
var currentTime = new Date()
currentTime.setDate(currentTime.getDate()+1);
for (var p = 0; p < this.numPages; p++)
{ var fd = this.addField("Date", "text", p, [100,10, 460,40]);
fd.textSize=12; fd.value = "UNCONTROLLED COPY - VALID UNTIL: " + util.printd("dd mmm yyyy", currentTime);
fd.allignment = "center"; fd.fillColor = color.black; fd.textColor = color.white; fd.display = display.noView;
var txtWillPrint = 'var d = this.dirty;\r'
+ 'var fd = this.getField("Date");\r'
+ 'fd.value = "UNCONTROLLED COPY - VALID UNTIL: " + '
+ 'util.printd("dd mmm yyyy", currentTime);\r'
+ 'this.dirty = d;';
this.setAction("WillPrint", txtWillPrint);
}
And the error messages:
InvalidGetError: Get not possible, invalid or unknown.
Doc.layout:7:Batch undefined:Exec
currentTime is not defined
3:Document-Actions:Document Will Print
currentTime is not defined
3:Document-Actions:Document Will Print
Thanks in advance.
Red
Offline

First the JavaScript Date object is not a number and not a date string, so you need to covert it to a number or get the year, month and date from the date object and then adjust the necessary values for 1 day. If you use the 'getTime()' or 'valueOf()' methods to get the date time value from the date object, the value will be in millisecods from the epoch date and not days. You can then add the necessary time interval in milliseconds to get a new date time value and then number can then be converted back to a date object and formatted.
/* Date Printed */
// get the current date object
var oCurrentTime = new Date()
// get the value for the number of milliseconds since the epoch date
var fCurrentTime = oCurrentTime.getTime();
// millisecondsmillisecondsadd 1 day in milliseconds
var fDay = 24 * 60 * 60 * 1000;
var fNextDay = fCurrentTime + fDay;
// create date object
var oNextDay = new Date(fNextay);
// show results
console.println('Now is: ' + oCurrentTime);
console.pmilliseconds addrintln('Tomarrow is: " + oNextDay);Or get use the parts of the date object:
/* Date Printed */ // get the current date object var oCurrentTime = new Date() // get the part of the date var fFullYear = oCurrentTime.getFullYear(); var fMonth = oCurrentTime.getMonth(); var fDate = oCurrentTime.getDate(); // create date object var oNextDay = new Date(fFullYear, fMonth, fDate + 1); // show results var sMsg = 'Now is: ' + oCurrentTime; sMsg += '\nTomorrow is: ' + oNextDay; app.alert(sMsg, 0, 1);
Offline

I think the problem is that you define currentTime in your general script (which you didn't say where you run it), but not in your embedded script. So when the embedded script is run, it can't find any variable called currentTime. Hence the error message.
Offline
Thanks for the helpful answers.
I revised the script and it is now running without bug. Here it is for info:
/* Date Printed */
// get the current date object
var oCurrentTime = new Date()
// get the part of the date
var fFullYear = oCurrentTime.getFullYear();
var fMonth = oCurrentTime.getMonth();
var fDate = oCurrentTime.getDate();
// create date object
var oNextDay = new Date(fFullYear, fMonth, fDate + 1);
/* Date Printed */
for (var p = 0; p < this.numPages; p++)
{ var fd = this.addField("Date", "text", p, [100,10, 460,40]);
fd.textSize=12; fd.value = "UNCONTROLLED COPY - VALID UNTIL: " + util.printd("dd mmm yyyy", oNextDay);
fd.allignment = "center"; fd.fillColor = color.black; fd.textColor = color.white; fd.display = display.noView;
//Print the date
var txtWillPrint = 'var d = this.dirty;\r'
+ 'var fd = this.getField("Date");\r'
'var fFullYear = oCurrentTime.getFullYear();'
+ 'var oNextDay = new Date(fFullYear, fMonth, fDate + 1);'
+ 'fd.value = "UNCONTROLLED COPY - VALID UNTIL: " + '
+ 'util.printd("dd mmm yyyy", oNextDay);\r'
+ 'this.dirty = d;';
this.setAction("WillPrint", txtWillPrint);
}
Offline