These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Javascript not working in Adobe Reader

vinayasopa1
Registered: Sep 29 2010
Posts: 2
Answered

Hi,
 
I have given the following javascript code in the "Will Save" Document Action. But this code does not execute in Adobe Reader, it works fine in Acrobat Standard/Pro. Why this code does not execute in Reader?
 
app.alert("Hi");
if(app.viewerVersion<8){
app.alert("Exit");
this.closeDoc(true);
}
 
Also,
1. How to set a javascript that executes when a pdf document is opened?
2. Should the priviledged javascipt always be folder level javscripts or document level javascript can also defined priviledged javascript?
 
Cheers,
Vinay

Cheers,
Vinay

My Product Information:
Reader, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Does the first alert appear at all? If not, is JavaScript enabled?
Also, how are you saving the file in Reader?

To answer the other questions:
1. You need Acrobat for that. You can either embed it manually using the Document JavaScript window, or in a script using the addScript() method.
2. You can place priviledged methods in document-level, but they will not have the same privileges as folder-level ones.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

vinayasopa1
Registered: Sep 29 2010
Posts: 2
Yes the javascript is enabled.

The alert comes up in Acrobat Pro when I use the 'Save' or 'Save a Copy option'. When I use the 'Save a Copy' option in Adobe reader, the alert does not come up.

For the other questions:
1. How do I associate the javascript to document open action. Can I get a sample code please.

Cheers,
Vinay

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You shouldn't close the document before it is supposed to save, that could potentially crash the application.

To add a script that is launched when the document is open, you can use something like this (run it from the console in Acrobat):

scriptName = "HelloScript";scriptCode = "app.alert('Hi!');";this.addScript(scriptName,scriptCode);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
try67 wrote:
1. You need Acrobat for that. You can either embed it manually using the Document JavaScript window
Scribus is also a nice (free) tool to do that : http://www.scribus.net/