Link to home
Start Free TrialLog in
Avatar of jerf26134
jerf26134

asked on

Close Acrobat with Javascript

I have a pdf document that opens, pulls information from a text file which populates the fields in the document, and then automatically prints.  I can get the pdf to close automatically, but I would like to close the Acrobat application instead.  Is there any way to close Acrobat with javascript?
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

No, you cannot do that. The App object does not have a "Quit" or "Close" method, and it's no longer possible to execute the menu item that would close Acrobat. So you have to live with Acrobat staying open after your document closes. As far as I know, there is also no mechanism to minimize the Acrobat window from JavaScript.
Forgot one thing: The "no longer possible" means that up to Acrobat 5 it was possible to execute that menu item from a JavaScript program. With Acrobat 6 Adobe decided to (for security reasons) no longer allow that.
Avatar of jerf26134
jerf26134

ASKER

That's what I was afraid of.  I can get Acrobat to close via a button using the execMenuItem, just not in a script when the page opens.  Do you know if there is any way to trigger a button on Page Open?  

If so, that would be just as good because I could set up a button that does not print and accomplishes the same thing.
Which version of Acrobat are you using? According to the documentation, this should no longer work.

Also, have you considered what happens if somebody already had Acrobat open when your document loads? If you try to quit Acrobat after the document closes, that will not take into account any other open documents. This may not be what the user wants.
I am using 7.0 but the majority of the users are still using 6.0 (which I haven't tested yet).  I have a line of javascript attached to the print button (this.print() ) and follow it up with an Execute a Menu Item - Exit.  It works in 7.0 which surprised me, but doesn't on Page Open, just Mouse Up.

This is in a mass production type of environment and most of the people dont have acrobat up with any other document while running this so that really isnt an issue for me.  I agree though that I would be extremely angry if I were working on another pdf and it suddenly closed without any warning.  Unfortunately we want to idiot-proof this as much as possible by taking as much of the user interaction out as possible...but they keep making better idiots.
I can only quote the JavaScript Reference: "For security reasons, scripts are not allowed to execute the Quit menu item" - this is from the 7.0.5 version of AcroJS.pdf. Adobe could consider the current behavior a bug and fix it in the next patch to Acrobat or Reader. I would not rely on this (undocumented) behavior in a commercial environment.
When I run the command app.execMenuItem("Quit"); in the JavaScript console, I get the following error:

app.execMenuItem("Quit");
NotAllowedError: Security settings prevent access to this property or method.
app.execMenuItem:1:Console undefined:Exec

This is with Acrobat 7.0.8 Professional. As far as I know, all restricted functions are allowed in a console environment.
I get the same error when its run from javascript, but what I have is a line of javascript that runs and after that finishes, a separate 'execute menu item' that isnt javascript closes the application.  So my button has the actions on MouseUp:
Run Javascript (which is the print part)
Execute Menu Item (Exit)

Is there a way for Acrobat to automatically act as if the button was pressed on openning the pdf?
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial