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

Need help with handling open/close/save/print events

Skurvy_Pirate
Registered: Jul 20 2009
Posts: 12

I'm trying to right a script that just handles these events and sends them out to another program I'm working on developing. This is surprisingly the first time I have ever worked with JavaScript but I'm picking it up ok.

I'm trying to use setAction to simply print a message to the console (for now) of when something is saved/opened etc. I have tried using something simple such as:

var myWillSave = console.println("WillSave");

this.setAction("WillSave", myWillSave);

as in the documentation, but I get an error:

this.setAction is not a function
3:Folder-Level:User:setAction.js

I am using Acrobat 9 and I have searched but can't seem to find what the problem is. I'm sure that I am missing something key but I don't know what it is. Any help is greatly appreciated.

My Product Information:
Acrobat Pro 9.1.1, Windows
Skurvy_Pirate
Registered: Jul 20 2009
Posts: 12
Ok, so I looked into it a little more and it looks like that is for document level JavaScripts. I want the same thing but application level so for any document that opens/closes/saves/prints I get events that I can send out. Basically like an addon to send out events. Is there something like these document events that I can use at the application level?

Thanks
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
In that case you need to create a function for your special actions, and then you can call those special functions from your application.

But if you want to distribute your forms to others, you will need to have them add your special functions to their application folders. This can be done by a system install script within your organization, but outside of your organization, you might not be able to use your special functions.

The best solution is to create some standard scripts as part of a stub or starter form that could be inserted into a new form and then delete the page of the stub form.

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You're not using this function correctly. The second argument (cScript) needs to be a String, which means that it has to be surrounded by single or double quotes.

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

Skurvy_Pirate
Registered: Jul 20 2009
Posts: 12
Is there a way to access these events from a script in the user folder? Our application could install the script there, then I would like it to send out those events from any document the user opened/closed etc. I would just like to capture the events the same way as with document level I guess. For now I want to print a message to the console for each event, then I will later work on sending them to the other app.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Yes with some coding you can add a menu item or tool bar button to add the script to a form you are creating. This can be difficult, because you need to define strings within a string and you should also make sure there is an open document to be processed. And you can use these folder level scripts in Reader.

The simpliest form of your document level script is:
// create a setAction script// set will save action using in line text string for codethis.setAction({cTrigger: "WillSave", cScript: "console.println(\"WillSave\");"});

And if you use a funciton for the script the coding can be simpler:

// define a function called myWillSave to be used by the set actionfunction myWillSave(){console.println("WillSave");return true;} // end myWillSave function // set will save action using document level functionthis.setAction({cTrigger: "WillSave", cScript: "myWillSave()"});

George Kaiser

Skurvy_Pirate
Registered: Jul 20 2009
Posts: 12
Ok, so it sounds like using JavaScript for this would be pretty tough. Would an actual plugin be able to access the open/close/save events of the Acrobat or Reader application? I don't want them to be document specific, so rather then when a certain document is open getting an open event, when you open any document from the Acrobat menu you get an open event.

Thanks