/ Id-Extras Forum / Document Action Close script?

  • Author
  • #6180 Reply

    I see how I can drop my JavaScript into FormMaker (this is very helpful), but I didn’t see a place where I can add a Document Action (Will Close) script. Is this possible?

    #6370 Reply
    Ariel
    Keymaster

    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):

    Code:
    // WillSave script
    var myWillSave = ‘var filesizeBeforeSave = this.filesize;r’
    + ‘console.println(“File size before saving is ” + ‘
    + ‘ filesizeBeforeSave );’;
    // DidSave script
    var myDidSave = ‘var filesizeAfterSave = this.filesize;r’
    + ‘console.println(“File size after saving is “‘
    + ‘filesizeAfterSave);r’
    + ‘var difference = filesizeAfterSave – filesizeBeforeSave;r’
    + ‘console.println(“The difference is ” + difference );r’
    + ‘if ( difference < 0 )rt' + 'console.println("Reduced filesize!");r' + 'elsert' + '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

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Document Action Close script?
Your information: