/ Id-Extras Forum / Document Action Close script? / Reply To: Document Action Close script?
Hi Mike,
When you say, “I can drop my JavaScript into FormMaker”, you mean that it’s possible to add a general “document”-level script right?
For now, it is true that there is no specific UI to add a Document Action. However, there’s a very simple workaround for this: When a document Javascript is added with FormMaker, it is run as soon as FormMaker is applied in Acrobat.
So the answer is to add your document “Will Close” action by creating a document script that adds it.
Once you’re ready to distribute the PDF, simply delete that particular document script from the PDF.
To add a document action script is really simple. Here’s an example of adding a “WillSave” and “DidSave” action (from the Acrobat SDK):
// WillSave script
var myWillSave = 'var filesizeBeforeSave = this.filesize;'
+ 'console.println("File size before saving is " + '
+ ' filesizeBeforeSave );';
// DidSave script
var myDidSave = 'var filesizeAfterSave = this.filesize;'
+ 'console.println("File size after saving is "'
+ 'filesizeAfterSave);'
+ 'var difference = filesizeAfterSave - filesizeBeforeSave;'
+ 'console.println("The difference is " + difference );'
+ 'if ( difference < 0 )'
+ 'console.println("Reduced filesize!");'
+ 'else'
+ 'console.println("Increased filesize!");'
// Set document actions...
this.setAction("WillSave", myWillSave);
this.setAction("DidSave", myDidSave);
… and for for “WillClose” you’d do exactly the same.
Does that make sense?
Ariel
-
This reply was modified 9 months, 3 weeks ago by
~~Ariel~~.
-
This reply was modified 9 months, 3 weeks ago by
~~Ariel~~.
-
This reply was modified 9 months, 3 weeks ago by
~~Ariel~~.
-
This reply was modified 9 months, 3 weeks ago by
~~Ariel~~. Reason: Fixed script formatting