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

Trusted Function Problem

nit
Registered: Apr 7 2009
Posts: 9

Hi,
I have a PDF when in i need to add run a javascript which combines 1 or 2 other PDFs
So i added script on the button
var newDoc = app.newDoc();
// Insert doc1.pdf:
newDoc.insertPages({
nPage: -1,
cPath: "/c/temp/doc1.pdf",
});
// Insert doc2.pdf:
newDoc.insertPages({
nPage: newDoc.numPages-1,
cPath: "/c/temp/doc2.pdf",
});
// Save the new document:
newDoc.saveAs({
cPath: "/c/temp/myNewDoc.pdf";
});

When clicked getting error that security settings prevent access to method or property
So i searched abt the error and found that this code has to be in batch or run in console or has to be in config.js file
So i added the code in as a Trusted Function and attached event to the button which calls that trusted function

But checking the debugger found that even if added my function as trusted and modified that config.js file it gives message in console that myTrustedFunction is not defined

Please help with any clue!!!

Thanks & Regards
nit

My Product Information:
Reader 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
First, to add a script to a PDF you need Acrobat Professional or Standard, so I have to assume that you have one of these?

Second, you can't define a trusted function in a PDF Script.

Third, none of the operations you've shown above can be done in Acrobat Reader. They can only be done in Acrobat Professional or Standard.

Read this article:
http://www.acrobatusers.com/tutorials/2008/10/using_trusted_functions

And this one:
http://www.acrobatusers.com/tutorials/2006/folder_level_scripts/

And this one has an example of creating an Acrobat toolbar button using a trusted function:
http://www.acrobatusers.com/tutorials/2007/10/apply_security_with_js

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to put them in a privilged context. So put a app.beginPriv() before and an app.endPriv() after your code.

(Edit: Of course, this doesn't apply if you use Reader...)

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

nit
Registered: Apr 7 2009
Posts: 9
Hi,
Actually i am using Acrobat Professional.
The first step what i did for my requirement was i added the script to button action,
when executed it gave me error saying that security settings prevent access to method or
property
So the next step what i did was i shfited that code to a config.js and made it as a Trusted Funtion
All these i had been doing in Acrobat Professional.
After that i added action to the buttin executing javascript where i call my trusted function.
My sample code in config.js goes like this

var mySaveDoc = app.trustedFunction(function(doc) {

var newDoc = app.newDoc();
newDoc.insertPages({
nPage: -1,
cPath: "/c/temp/doc1.pdf"
});

newDoc.insertPages({
nPage: newDoc.numPages-1,
cPath: "/c/temp/doc2.pdf"
});

newDoc.saveAs({
cPath: "/c/temp/myDoc.pdf"


});

newDoc.closeDoc(true);
});

and the MouseUp of button executes a javascript as below

mySaveDoc(doc);

I modifed and saved the .js file and reopened the PDF so that changes are reflected properly
So when i click the button then i get message/error saying that "mySaveDoc" is not defined
Also tried adding the app.beginPriv(); and endPrev(); then too same error.
Not only this even if i have only app.alert() in my trusted function then too same error is displayed
The script section in debugger console prolery show the code which i written in the script text area.

Is there any thing which has to be taken care of
Please help!

regards
nit
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Where did you put app.beginPriv() and endPriv()?
Post the full code.

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

nit
Registered: Apr 7 2009
Posts: 9
Hi,
Code with beginPriv() and endPriv()


var mySaveDoc = app.trustedFunction(function(doc) {

app.beginPriv();

var newDoc = app.newDoc();
newDoc.insertPages({
nPage: -1,
cPath: "/c/temp/doc1.pdf"
});newDoc.insertPages({
nPage: newDoc.numPages-1,
cPath: "/c/temp/doc2.pdf"
});newDoc.saveAs({
cPath: "/c/temp/myDoc.pdf"


});
app.endPriv();
newDoc.closeDoc(true);
});