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


 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.


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."; 
    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: 9.8/10 (4 votes cast)
Acrobat/Reader: how to close a PDF automatically through Javascript, 9.8 out of 10 based on 4 ratings

Comments are closed.