Question
How to run a document-level javascript?
I am trying to run a script that will extract all field names, their location, page, and type. How and exactly where would I add this script? I tried going to:
Tools > JavaScript > Document JavaScripts > Add
But this does not allow me to run a scrip, only to add or edit one. Can someone please help or point me to the documentation? Thanks.
Here is my script given by chat GPT:
function Extract()
{var allFields = this.getFields();
var fieldInfo = [];
for (var fieldName in allFields) {
var field = allFields[fieldName];
var rect = field.rect;
fieldInfo.push({
"Name": field.name,
"Type": field.type,
"Page": field.page + 1, // Acrobat's page index starts at 0, so adding 1 to make it human-readable
});
}
if (fieldInfo.length > 0) {
var output = "Name,Type,Page\n";
for (var i = 0; i < fieldInfo.length; i++) {
var info = fieldInfo[i];
output += info.Name + "," + info.Type + "," + info.Page + "\n";
}
// Save the CSV string to a file.
var file = new File(app.activeDocument.path + ".csv");
file.open("w");
file.write(output);
file.close();
} else {
console.println("No fields found.");
}
}
