Copy link to clipboard
Copied
Hi all,
I have to mark more than 1000 elements in an PDF as decorative. I try a JavaScript printed here:
/*
* This script iterates through all annotations in a tagged PDF document.
* It checks whether annotations lack alternative text and marks them as decorative.
* This script is designed to run in the Adobe Acrobat Pro debugger.
*/
// Check if the document has a tag tree
var doc = this;
if (!doc.catalog.spans) {
console.println("This document does not have a tag tree. Please ensure the document is properly tagged before running this script.");
} else {
// Get the total number of annotations in the document
var numAnnotations = doc.numAnnots;
if (numAnnotations === 0) {
console.println("No annotations are found in this document.");
} else {
console.println("Processing annotations...");
for (var i = 0; i < numAnnotations; i++) {
// Access each annotation
var annotation = doc.getAnnot(i);
if (annotation !== null) {
// Check if the annotation contains an 'Alt' key (alternative text)
if (!annotation.alt || annotation.alt.trim() === "") {
// If no alternative text, mark it as decorative
annotation.setProps({
Contents: "Marking as decorative",
alt: "", // Ensure Alt is empty
flags: annotation.flags | 0x10 // Add the decorative flag (bitmask)
});
console.println("Annotation on page " + (annotation.page + 1) + " marked as decorative.");
} else {
console.println("Annotation on page " + (annotation.page + 1) + " already has alternative text.");
}
}
}
console.println("Processing completed.");
}
}
But the output is:
This document does not have a tag tree. Please ensure the document is properly tagged before running this script.
true
In the folowing picture you can see that I'm using Adobe Acrobat Pro and that my Document has also a Tag-Tree. Of course it is not the document with more than 1000 elements but the script should also work with this small document.
Maybe one of you could help me with my problem.
Regards Norbert
Copy link to clipboard
Copied
this.catalog gives you the access of the search catalog. This has nothing to do with the tag tree.
Copy link to clipboard
Copied
There is no numAnnots document property. Try doc.getAnnots().length;
Copy link to clipboard
Copied
Tags can't be accessed using a script. This is probably some AI hallucination code.
Copy link to clipboard
Copied
I believe that Try67 is correct. You have used an AI to generate nonsensical code and are now asking us to fix it.
Besides the incorrect item mentioned by Bernd, there are several non-existant properties used in the code. And the stated purpose of the code makes no sense. This code is truely a meaningless pile of crap.
I would suggest you ask the AI to fix it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now