Solved

Close Acrobat with Javascript

Posted on 2006-06-28
11
2,871 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
11 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17002727
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
ID: 17002749
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
ID: 17003577
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
Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17003627
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
 

Author Comment

by:jerf26134
ID: 17005198
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
ID: 17008561
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
ID: 17008588
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
ID: 17010978
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
ID: 17011299
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…

749 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