6 Replies Latest reply on Nov 8, 2017 5:07 PM by Karl Heinz Kremer

    openDoc not allowing me to access doc variable

    henrygw

      Apologies - this is probably very basic but I can't find a solution anywhere for this.  I'm running a script from user / privileged directory.  Purpose of the script will be to run through a large number of files and add a comments box to each one.  However, I'm falling over at the first hurdle.

       

      I open acrobat and the file "s.pdf" is opened automatically.  However, script stops at the next line with message:

       

      "TypeError: myDoc is undefined

      2:Folder-Level:User:java_file.js"

       

      addAnnot line runs fine from console using "this" rather than myDoc.  Any idea why this isn't working?

       

      Full script is below.  Plan is to extend this to include a large number of files each with unique comments.

       

      [in java_file.js]

      1.  var myDoc = app.openDoc("/C/MyTemporaryFolder/s.pdf");

      2.  myDoc.addAnnot({type:"FreeText",page:0,rect:[0,1142-200,200,1142],contents:"The quick brown fox"});

      3.  mySaveAs(myDoc,"/C/MyTemporaryFolder/","te.pdf");

      4.  myDoc.closeDoc(true);

       

       

      [in a separate file] - save function works fine from the console.

      var mySaveAs = app.trustedFunction(

         function(oDoc,cPath,cFlName)

         {

            app.beginPriv();

            // Ensure path has trailing "/"

            cPath = cPath.replace(/([^/])$/, "$1/");

            try{

               oDoc.saveAs(cPath + cFlName);

            }catch(e){

               app.alert("Error During Save");

            }

             app.endPriv();

         }

      );