Answered
I am trying to create a document level script that when it is opened, I want it to open another document.
In the first document (ScriptTest.pdf) the following is in the document script area:
//<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" }); var myDocument = myTrustedOpen(); function OpenEvent() { } //</ACRO_script> //</Document-Level>
In a trusted folder
(C:\Documents and Settings\jdawson\Application Data\Adobe\Acrobat\8.0
\JavaScripts)
The file config.js contains the following code:
app.alert({ nIcon: 2, nType: 0, cMsg: "Application Started.", cTitle: "APP START" }); myTrustedOpen = app.trustedFunction( function() { app.beginPriv(); app.alert({ nIcon: 2, nType: 0, cMsg: "This is a trusted function.", cTitle: "TRUSTED FUNCTION" }); var myDoc = app.openDoc({ cPath: "/C/Documents and Settings/jdawson/My Documents/Test/smalldocument.pdf", bHidden: false }); app.endPriv(); return myDoc; } );
When ScriptTest.pdf is opened, three alerts are displayed titled:
1. "APP START"
2. "TRUSTED FUNCTION"
3. "OPEN EVENT"
Then an error message as follows:
NotAllowedError: Security settings prevent access to this property or method.
App.openDoc:20:Document-Level:OpenEvent
When I close the script editor with ScriptTest.pdf already open, it seems to work fine.
I thought this should work. If someone can help me get this correct I would be very grateful.
Sincerely,
Jim
The solution is to place the "openDoc" code in the page "Open" event for the first page in the PDF. The page Open event happens after the document has been initialized. Make sure you add a state variable to the open action so the open doesn't happen a second time. For example:
if(this.bAlreadyOpened == null)
{
app.openDoc("/C/Documents and Settings/jdawson/My Documents/Test/smalldocument.pdf");
this.bAlreadyOpened = true;
}
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script