Acrobat/Reader: how to close a PDF automatically through Javascript

Issue

 If you are trying to close a PDF automatically using Javascript you may encounter differing behaviour depending on whether you are using Acrobat or Reader, and of course, depending on the version.

Solution

You should use the setTimeOut() method with the action defined as closeDoc().  The setTimeOut() method must be assigned to a variable in a top level object in the form, to prevent it from being garbage collected when a lower level variable goes out of scope.

In the form:ready event you should add the following script:

var discard = soUtils.closeDoc();

and then create a new Script object on the form with the following code:

function closeDoc()
{
    var str = "This document will now close."; 
    app.alert(str); 
    return app.setTimeOut('this.closeDoc();', 1);
}

Then the PDF should automatically close itself when opened in Acrobat/Reader.

VN:F [1.9.22_1171]
Was this helpful? Please rate the content.
Rating: 10.0/10 (3 votes cast)
Acrobat/Reader: how to close a PDF automatically through Javascript, 10.0 out of 10 based on 3 ratings

Comments are closed.