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

    openDoc not allowing me to access doc variable

    henrygw Level 1

      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



      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(




            // Ensure path has trailing "/"

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


               oDoc.saveAs(cPath + cFlName);


               app.alert("Error During Save");