openDoc not allowing me to access doc variable

New Here ,
Nov 07, 2017

Copy link to clipboard

Copied

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

   }

);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

139

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

openDoc not allowing me to access doc variable

New Here ,
Nov 07, 2017

Copy link to clipboard

Copied

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

   }

);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

140

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 07, 2017 0
Most Valuable Participant ,
Nov 08, 2017

Copy link to clipboard

Copied

The file you're opening must be disclosed.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
New Here ,
Nov 08, 2017

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
Most Valuable Participant ,
Nov 08, 2017

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
Adobe Community Professional ,
Nov 08, 2017

Copy link to clipboard

Copied

A better method to perform this task (because you don’t have to open a large number of files to add the disclosed statement) is to use an Action to perform this task of adding the annotations. You can create a data structure that maps a filename to the annotation(s) you want to add. Then just run it on eg all files in a directory and check if the file and is in your data structure.

You oh can also use the Action to add the disclosed statement to many files in one operation if you choose to go that route.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
New Here ,
Nov 08, 2017

Copy link to clipboard

Copied

The only option I get under the javascript tools is "Set Document Actions"  I'm running acrobat XI standard, is this a version limitation?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
Adobe Community Professional ,
Nov 08, 2017

Copy link to clipboard

Copied

Yes, Acrobat Standard does not support document level scripts. You can use this tool to get around this limitation: Document Level Scripts With Acrobat Standard - KHKonsulting LLC

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0