Solved

Close Acrobat with Javascript

Posted on 2006-06-28
11
2,797 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:jerf26134
  • 6
  • 3
11 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
 

Author Comment

by:jerf26134
Comment Utility
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.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:jerf26134
Comment Utility
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.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
 

Author Comment

by:jerf26134
Comment Utility
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?
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
Comment Utility
I see, you are not using JavaScript. That's interesting. I did not know that they allow that.

As far as I know, you cannot execute a button without user interaction. I am not aware of a JavaScript command that would do that, but I also don't know of any plug-in API function that would allow you to execute a button.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The ability to edit PDF documents can be useful, however it may not be a straight forward process. Many non-technical people don't realise that a PDF document is basically an image rather than a text file, even if it contains nothing but text. If…
*Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now