Skip to main content
Participant
November 8, 2017
Question

openDoc not allowing me to access doc variable

  • November 8, 2017
  • 1 reply
  • 597 views

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();

   }

);

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
November 8, 2017

The file you're opening must be disclosed.

henrygwAuthor
Participant
November 8, 2017

Thanks try67 - how do I make the file disclosed then?

try67
Community Expert
Community Expert
November 8, 2017

Open the target file, go to Tools - JavaScript - Document JavaScripts and create a new item (let's call it "disclose", for example) with this code:

this.disclosed = true;

Save the file and try again.