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

Adobe Save functionality using button event.

madhan1211
Registered: Oct 13 2008
Posts: 8

Hi,

I am using Adobe reader 8.1.2. I am using Adobe livecycle designer to write the javascript for the button event. My requirment is when I click the button "Save" the Adobe form should be saved in a specific path. I am able to invoke the similar functionality using the menu event. Could you please help me to implement the similar functionality with the button event.When I click the button to save the Adobe form the following error message is displayed.

The error message is :Security settings prevent access to this property or method.

The below code is available in eDoc.js file @ C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts

app.addMenuItem( { cName: "eDocSave", cUser: "Save eDoc", cParent: "File", cExec: "edocSave()", nPos: "Close"} );

function edocSave() {

app.alert("This is a begining");
var myDoc = event.target;
//app.alert("This is a first list");
var myDoc = event.target;
var strPath = "/c/Adobe/";
app.alert(strPath);
//var objField = myDoc.getField("F[0].P1[0].SaveLocation[0]");
//app.alert(objField);
var strFile = strPath + "test123.pdf";
app.alert(strFile);

try {
app.alert("Before Save As: " + strFile);
fnMakePDF(myDoc,"/c/Adobe/TestFile.pdf");
//myDoc.saveAs(strFile);
} catch (E) {
for (var i in E)
app.alert(i + ": " + E[i]);
}
}

fnMakePDF = app.trustedFunction( function (doc,outFile)
{
app.beginPriv();

mySaveAs(doc,outFile); // Save it (or overwrite old)

console.println("\nThere are " + doc.numFields + " Fields in this document");

//doc.closeDoc(true); // close the document
//doc = undefined;

app.endPriv();
return;

}); // END function fnMakePDF

mySaveAs = app.trustPropagatorFunction(function(doc,outFile)
{
app.beginPriv();
doc.saveAs({cPath: outFile});
app.endPriv();
});

The Javascript available for the button onClick event @ Adobe Livecycle Designer.

try
{
app.beginPriv();
var docinfo=event.target;
fnMakePDF(docinfo,strFileName );
app.endPriv();
}
catch (E) {
for (var i in E)
app.alert(i + ": " + E[i]);
}

Please let me know if there is any alternative approach to save the Adobe form using the onClick event on Button.

Thanks
Madhan

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
1. There can be differences between vendor supplied scripts and and thate Adobe has 2 different programs, Acrobat and LiveCycle Designer, that have different languages and syntax.

2. User written script may not be coded in the same manner as appliction supplied scripts. There are

3. There are significant differences between Acrobat's and Reader's furnctionality, especailly around the "save as" in a form.

For a user to use the "saveAs()" method for version , the user written code needs to be placed in an Acrobat/Reader application level JavaScript folder and the user must create a trusted function and use the privlage method.

All of this is contained in the Acrobat JavaScript documentation.

George Kaiser

madhan1211
Registered: Oct 13 2008
Posts: 8
Thanks for the quick response.

I have tried the approach you suggested by placing the code snippet in trusted functions and invoking the method on event.

Here is the code snippet to invoke the function onClick of button event.


try
{
app.beginPriv();
var docinfo=event.target;
fnMakePDF(docinfo,strFileName );
app.endPriv();
}
catch (E) {
for (var i in E)
app.alert(i + ": " + E[i]);
}

fnMakePDF(docinfo,strFileName ); is implemented in trusted function and placed in application Javascript folder C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts.

Still I am getting the same error :Security settings prevent access to this property or method.

Thanks,
Madhan
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You have not created a "trustedFunciton" and you have to keep all of the function calls within trusted functions and privileged operations:

// the following functions need to be placed in either the Acrobat/Reader application or user JavaScript Folder:
mySaveAs = app.trustPropagatorFunction(function(doc,path)
{
app.beginPriv();
doc.saveAs(path);
app.endPriv();
})

myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path)
{
// privileged and/or non-privileged code above
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
// privileged and/or non-privileged code below
});
// end of folder level code

Now, executing the code:

myTrustedSpecialTaskFunc(this, "/c/temp/mySavedDoc.pdf");

from a mouse-up button, for example, saves the current document to the specified path.

As to why all of this code is needed, please see the Acrobat JavaScript Reference.

If you are using Reader, the PDF you will be using to execute this code requires special processing to create a PDF with special Reader Extensions.

George Kaiser

madhan1211
Registered: Oct 13 2008
Posts: 8
Hi kaiseril,

Thanks for your suggestion. I have tried couple of ways to implement the suggestion as given by you.

First Option:-
1) I have placed the code snippet at C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts\eDocs.js file and executed. Still I am getting the same error :Security settings prevent access to this property or method.

Second Option:-
2) I have placed the code snippet directly under button>Click event in Adobe Livecycle designer like shown below,Still I am getting the same error :Security settings prevent access to this property or method.mySaveAs = app.trustPropagatorFunction(function(doc,path)
{
app.alert("begin2");
app.beginPriv();
doc.saveAs(path);
app.endPriv();
app.alert("end2");
})

myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path)
{
// privileged and/or non-privileged code above
app.alert("begin");
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
app.alert("end");
// privileged and/or non-privileged code below
});

myTrustedSpecialTaskFunc(this, "/c/Adobe/mySavedDoc.pdf");

I have follwed the Acrobat javascript refernece http://www.adobe.com/devnet/acrobat/pdfs/js_api_reference.pdf but it didn't help.

You have mentioned Special Reader Extensions for Adobe Reader 8.10.2 to execute the script. How can I do that. Is Special Reader Extensions required to execute the script.

Please let me know your inputs to get this save functionality implemented.

Thanks,
Madhan
Bhaskaran
Registered: Jun 27 2011
Posts: 1
HI, iam also facing the same issue. can you please help me to find the solution.