Skip to main content
Sturm359
Inspiring
May 23, 2017
Answered

getAnnots() returns null in script

  • May 23, 2017
  • 1 reply
  • 1721 views

This one completely baffles me. When run inside the console, it works. When called from a framing script, it does not.

I have a pdf document that contains a stamp. I wish to "get" that stamp so I can clone it into a different document. But here's where I run into a problem: Getting the annotations from the Javascript Console inside Acrobat DC...:

var refDoc = app.openDoc("/ArtDept/ArtDept/JOBS/462000-462999/462000/CS/493130_T-N10-WHITE_CartoonNetwork_SPEC.pdf");

console.println("refDoc is: " + refDoc);

console.println("refDoc's name is: " + refDoc.documentFileName);

var refAnnots = refDoc.getAnnots();

console.println("refAnnots: " + refAnnots);

works fine. `refAnnots` shows me a list of all the annotations (stamps included) in the document.

If I run the *exact same code* inside of a much larger script, `refAnnots` is null. Meaning that the script couldn't find any annotations in the document.

I've already made sure that the code sits inside of `app.beginPriv();` and `app.endPriv();` lines as well as being inside a function that is defined inside of `app.trustedFunction()`. All of this is in a file that is in the application-level folder. Thus, security should not be an issue. Everything else inside this function works perfectly.

This topic has been closed for replies.
Correct answer try67

Is the document disclosed? What does the second line produce when you run this code not from the console?

Also, it's recommended to execute syncAnnotScan before accessing the annotations in a file.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 23, 2017

Is the document disclosed? What does the second line produce when you run this code not from the console?

Also, it's recommended to execute syncAnnotScan before accessing the annotations in a file.

Sturm359
Sturm359Author
Inspiring
May 23, 2017

Hey, thanks for the rapid response, try67​!

Yes, the document is disclosed. The second and third lines produce the exact same effect, whether or not it's done through the script or through the console.

However, I did discover that you are correct about `syncAnnotScan()`. I placed that before the fourth line in my initial code and that caused the stamp to *finally* be recognized. Yay! One more hurdle down!

I now have a new problem, however, and that is stopping Acrobat DC from *crashing* literally every time it is trying to save the other document (after the stamp has been cloned to it). Perhaps I should post this as a separate question, though.