I've searched the forums but can't seem to find what I need. I found the original script here and modified it slightly to fit what I need besides one detail. I have this as a Batch Process as I will have to apply this to multiple documents. Right now, it will save it with the date and time the batch is run, then updates the date when it's printed. I would like to have the date updated when the document is opened as well. If you are able to help me with this, that would be greatly appreciated. Thanks for taking a look!
for (var p = 0; p < this.numPages; p++)
var fd = this.addField("Date", "text", p, [72,66,540,50]);
fd.value = "This is a Controlled Document. Printed copies are valid for 24hrs past: " + util.printd('dddd dd mmmm yyyy h:MM tt', new Date());
fd.allignment = "right";
fd.fillColor = color.transparent;
fd.textColor = color.red;
fd.borderColor = color.red;
fd.readonly = true;
var txtWillPrint = 'var d = this.dirty;\r'
+ 'var fd = this.getField("Date");\r'
+ 'fd.value = "This is a Controlled Document. Printed copies are valid for 24hrs past: " + '
+ 'util.printd("dddd mmmm dd yyyy h:MM tt", new Date());\r'
+ 'this.dirty = d;';
Simply add a document-level script using the doc.addScript method that adds the same code as you do with the setAction method in your current code.
How would I do that? Unfortunately I know nothing of scripting and found my current code on these forums.
For the last two lines of your script, use:
this.setAction("WillPrint", txtWillPrint); // You already have this
this.addScript("init", txtWillPrint); // This adds document-level script
The addScript method is documented here: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.440.html
This new document-level script will execute whenever the document is opened and will update the date field that you add with the current date/time.