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

NotAllowedError when trying to use browseForDoc in a batch sequence

dpb
Registered: Jul 8 2009
Posts: 7
Answered

Hello,

I'm trying to run a batch sequence that automatically finds a cover file and inserts it as the first page of a document. I'm doing this assuming that filenaming conventions have been followed, so to build in a failsafe for the script I have tried to allow the user to select the file using browseForDoc if the file is not found.

The code works as expected from the console, but won't run from a batch process - browseForDoc generates a NotAllowedError. Any ideas why? I have done some brief testing calling browseForDoc as a trusted function, which i think will work but I'd love to understand why it won't work from a batch normally.

I've inserted my code below:

 
global.sWorkingPath = (this.path);
global.setPersistent("sWorkingPath",false);
global.sIdealCoverPath = this.path.replace("-text-working","-cover-working"); 
global.setPersistent("sIdealCoverPath",false);
//Get the name of the current file, assume it ends with "text-working.pdf" 
//and try to rename it to "cover-working.pdf" so the cover file can be inserted.	
 
/* Now test the filename to see if the cover can be inserted automatically, on error, prompt user to select file*/
 
/* The var global.sIdealCoverPath specifies the cover file to be inserted.*/
 
console.println("Attempting to automatically insert cover file for " + this.documentFileName);
 
var bCoverInserted = 0; //this variable will be switched to 1 if the cover is inserted successfully to skip further attempts at insertion that occur later in the script.
 
/* Now check that the rename has in fact changed the filename. If the rename has failed, throw 
an exception because the next step will fail without a correctly named file.*/
 
try {
 
      if (this.path == global.sIdealCoverPath) 
      throw "Cover file for " + this.documentFileName + " not found.\n Please ensure you follow the file naming guidelines, " + 
      "using '-text-working.pdf' and '-cover-working.pdf'.\n You will now be directed to select the cover file  manually.";
    } 
catch(e) 
    {
//alert the user to the problem, prompt them to insert the file, then run a script saving the  file as ebook-working.pdf
        app.alert(e);
 
//get the user to browse for the cover file, then use that information to insert that cover into the current document
 
        try
        {    
            var oBrowseForCover = app.browseForDoc({bSave: false, cFilenameInit: "",cFSInit: "",});
            if     ( typeof oBrowseForCover != "undefined" )
            for    ( var o in oBrowseForCover )
                    console.println( "oBrowseForCover." + o + "=" + oBrowseForCover[o]);
            else    {console.println("User cancelled browsing for cover!");
                    event.rc = false;}
        }
        catch(e)
        {
            console.println(e)
            for (var i in e)
            console.println( i + ": " + e[i])
        }

My Product Information:
Acrobat Pro 8.1.3, Windows
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
You have a syntax error in this command:
app.browseForDoc({bSave: false, cFilenameInit: "",cFSInit: "",});

You need to remove the last comma. Also, I think you should not specify cFilenameInit as an empty string. It might also cause a problem.

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

dpb
Registered: Jul 8 2009
Posts: 7
Thanks for that try67,

Unfortunately that syntax error doesn't appear to the problem.

browseForDoc gives me a Not Allowed Error even if it's the only command with or without the arguments bSave, cFilenameInit and cFSInit.

If i try to run this
app.browseForDoc("false","test");
or this
app.browseForDoc();
This is what the console spits out

NotAllowedError: Security settings prevent access to this property or method.app.browseForDoc:1:Batch undefined:Exec
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
Try putting it inside a trusted function.

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

dpb
Registered: Jul 8 2009
Posts: 7
I put it in a trusted function and it now works.... Any ideas why I can call it successfully from the console but not a batch function?
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
It shouldn't be according to the documentation, but sometimes there are undocumented (or badly documented) security restrictions on certain methods.

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