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

SaveAs using app.TrustedFunction method

jdawson422
Registered: Feb 18 2008
Posts: 12

I am trying to use one file (ScriptTest.pdf) to open a second file and save the second file as a new document.

Well, I got the opening of the document working. Thanks to thomp. (See my previously posted topic.)

Now, saving it to a new file is giving me problems. And this is where I am using the trustedFunction method.

In the config.js file I have:

myTrustedSaveAs = app.trustedFunction(
    function(adoc)
    {
        app.beginPriv();
            var myTrustedRetn = adoc.saveAs({
            cpath: "/C/Documents and Settings/jdawson/My Documents/Test/doc_ver8.pdf",
            bPromptToOverwrite: False
        });
        app.endPriv();
        return myTrustedRetn;
    }
);

I added one line to ScriptTest.pdf to give:

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------
 
//<Document-Level>
//<ACRO_source>OpenEvent</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:OpenEvent ***********/
app.alert({
    nIcon: 2,
    nType: 0,
    cMsg: "You just opened this document.",
    cTitle: "OPEN EVENT"
});
 
function OpenEvent()
{
}
//</ACRO_script>
//</Document-Level>
 
//<Page-Actions>
//<ACRO_source>Page1:Page Open:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: Page-Actions:Page1:Page Open:Action1 ***********/
if(this.bAlreadyOpened == null)
{
   var myDoc = app.openDoc("/C/Documents and Settings/jdawson/My Documents/Test/smalldocument.pdf");
//Added the one new line below
   var newDoc = myTrustedSaveAs(myDoc);
   this.bAlreadyOpened = true;
}
 
//</ACRO_script>
//</Page-Actions>

When I open ScriptTest.pdf I get the alert (sort of a debugging aid for now) and then this error message comes up:

Quote:

Acrobat JavaScript Debugger Functions Version 7.0
Acrobat Database Connectivity Built-in Functions Version 8.0
Acrobat EScript Built-in Functions Version 8.0
Acrobat Annotations / Collaboration Built-in Functions Version 8.0
Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0
Acrobat Multimedia Version 8.0
Acrobat SOAP 8.0

adoc has no properties
5:Folder-Level:User:config.js
adoc has no properties
5:Folder-Level:User:config.js

The file smalldocument.pdf does open successfully, by the way.

Thanks again for the generous help.

My Product Information:
Acrobat Pro 8.1, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
The message is explaining that either you did not pass the expected "adhoc" parameter or the value you passed does not exist. The error is occuring at line 5 of your script in the user appliction JS file "config.js".

It appears your function is expecting the object name of the second file you opened. "The call to your function should be like:

var myFile = app.openDoc("myDoc.pdf", this);myTrustedSaveAs(myFile)

George Kaiser

jdawson422
Registered: Feb 18 2008
Posts: 12
I tried what you (gkaiseril) suggested with no luck. thomp (another user) mentioned that app.openDoc returns null if this.disclosed is not true. So I tried some instances of this.disclosed = true at both the doc open event and at the page open event with no luck.

I tried this with no other code other than the xml tags, etc. already present in a new document.

this.disclosed = true;var myDoc;if(this.bAlreadyOpened == null){myDoc = app.openDoc({cPath:"/C/Documents and Settings/jdawson/My Documents/Test/smalldocument.pdf",bHidden: true});this.bAlreadyOpened = true;if(myDoc == null){app.alert({nIcon: 2,nType: 0,cMsg: "myDoc == null",cTitle: "NULL OBJECT"});}}

The smalldocument.pdf opens and the alert is displayed. I therefore assume that I am placing the code in the page/open area of the code.

But I think is shows that app.openDoc is returning null even though I included this.disclosed = true.

For such a simple thing, this sure is baffling.
jbfreels
Registered: Feb 19 2008
Posts: 63
FWIW, I can only get the variable to be valid when I pass oDoc with the app.openDoc method. Inconvenient in a lot of cases, but works for me.