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();
}
);
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();
}
);
Copy link to clipboard
Copied
The file you're opening must be disclosed.
Copy link to clipboard
Copied
Thanks try67 - how do I make the file disclosed then?
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.
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.
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?
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