I have written a couple of trusted "app-level" JavaScript functions, mostly to perform silent saves and reads from XFA type forms. The scripts do work as expected when associated with menu items or buttons from within standard Acrobat 8.
My trusted JavaScript functions use this technique:
myExportXFAData = app.trustPropagatorFunction(function(oDoc, sPath, bXDP, sPackets)
{
app.beginPriv(); // explicitly raise privilege
oDoc.exportXFAData(sPath, bXDP);
app.endPriv();
});
TrustedExportXFAData = app.trustedFunction(function(oDoc, sPath, bXDP, sPackets)
{
var bSuccess = false;
app.beginPriv();
try {
myExportXFAData(oDoc, sPath, bXDP, sPackets);
bSuccess = true;
}
catch(e){
app.alert(sPath + " NOT exported!\n" + e.message + "\n" + e.name);
}
app.endPriv();
return( bSuccess );
});
However, what I really need to do is perform those same functions but trigger them from my hosting VB application's menu items and toolbars.
When I try this:
Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
ok = AcroExchAVDoc.OpenInWindowEx(sFullPathName, Me.hWnd, CLng(AV_page_view), True, 0, CInt(PDUseBookmarks), CInt(AVZoomFitWidth), 0, 0, 0)
Set AcroPDDoc = AcroExchAVDoc.GetPDDoc
Set jso = AcroPDDoc.GetJSObject
If jso.dynamicxfaform Then
rc = jso.TrustedExportXFAData(AcroPDDoc, sFilePath, True, "datasets")
End If
I find that the trusted JavaScript does indeed execute, but it throws the exeception:
"Run-time error '1001':
NotAllowedError: Security settings prevent access to this property or method."
My objective is to save the XFA data to a known and safe path, so that it can be reloaded and displayed later (and saved to a database).
Any help on this would be greatly appreciated.
There is really only one way to create a trusted function, i.e., in a Folder Level script. All other scripts are suspect and are therefore a security risk.
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script