These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

execute javascript with action wizard

dogrumustafa
Registered: Jan 3 2011
Posts: 7
Answered

I have several files in a folder. I want to change strokeColor of each annotation to blue on the first page.
on the action wizard window I checked promt user, each file opened in acrobat script run succesfully. with promt user unchecked it is not running.
  
var annots = this.getAnnots({ nPage:0 });
for (var i = 0; i < annots.length; i++){
annots[i].popupRect
annots[i].setProps({strokeColor: color.blue});
};

My Product Information:
Acrobat Pro 10.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Get ride of the "annots[i].popupRect" line. It doesn't do anything.

Try this code:

try{
var annots = this.getAnnots({ nPage:0 });
console.println(annots.length + " Annots Found");
for (var i = 0; i < annots.length; i++){
annots[i].strokeColor = color.blue;
}
}catch(e){
console.println("ERROR: " + e);
}


It includes an error check that may provide some info. Look in the console while the Action is running

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

dogrumustafa
Registered: Jan 3 2011
Posts: 7
hello thom thanks for your replay
I used following code for batch processing
in the console I get ERROR: TypeError: annots is null
in the batch process annotations are not accesible

try{
var annots = this.getAnnots({ nPage:0 });
console.println(annots.length + " Annots Found");
for (var i = 0; i < annots.length; i++){
annots[i].strokeColor = color.blue;
}
}catch(e){
console.println("ERROR: " + e);
}

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you read the reference entry for doc.getAnnots you'll see that it returns null when there are no annots on a page. So, the most logical conclusion is that there are no annotations on page 0 of that particular document.


Add a test to the code so that the loop only runs when annots is non null.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

dogrumustafa
Registered: Jan 3 2011
Posts: 7
there annotations on the first page
I am running this code from the action wizard for the batch process
as i mentioned in the first post, if i check "promt user" option then run the code, no problem it finds annotations on each page and does the process


thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I'm going to do some testing later today on this to see if I can repeat the issue.

But you should try a new approach. Add an instruction step immediately before the JavaScript step in the Action. See if this has the same effect as "prompting" the user

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
Ok, I feel like a dunce. I already knew the answer to this one and I keep forgetting it. It's even shown in the "doc.getAnnots()" example in the AcroJS Ref.

Acrobat loads the Annotations last. But it recognizes the PDF as loaded and ready before loading the Annots. I don't know why they did this, but it means it's very easy to start a script running before the Annots are available. To mitigate this issue there is a document function that simply waits for the annots to load.

Try this code:

try{
  this.syncAnnotScan();

  var annots = this.getAnnots(0);
  for (var i = 0; i < annots.length; i++)
    annots[i].strokeColor = color.blue;
}catch(e){
   console.println("ERROR: " + e);
}

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

dogrumustafa
Registered: Jan 3 2011
Posts: 7
thanks a lot. it is very valuable information for me. I spent my two days I could not find the way