Copy link to clipboard
Copied
Hi there together, we have following Problem:
we need a Javascript to rename all layers with name "name1" to "name2" and then save the PDF file.
Any help would be greatly appreciated.
Thanks you very much,
Patrick
This code will rename the layer:
var ocgArray = this.getOCGs();
for (var i=0; i<ocgArray.length; i++) {
if (ocgArray.name=="name1") {
ocgArray.name = "name2";
break;
}
}
Saving the file afterwards is more complicated. You can use the saveAs command from a trusted context to do it silently, or you can call the Save As dialog and let the user do it manually, using the app.execMenuItem("SaveAs") command.
Copy link to clipboard
Copied
This code will rename the layer:
var ocgArray = this.getOCGs();
for (var i=0; i<ocgArray.length; i++) {
if (ocgArray.name=="name1") {
ocgArray.name = "name2";
break;
}
}
Saving the file afterwards is more complicated. You can use the saveAs command from a trusted context to do it silently, or you can call the Save As dialog and let the user do it manually, using the app.execMenuItem("SaveAs") command.
Copy link to clipboard
Copied
Hi try67,
thanks for the quick response, but it seems there is something missing at the beginning:
this.getOCGs is not a function
how do i run it from extendscript-toolkit? it is originally intended to run from Enfocus-Switch, which can execute Javascripts in all Adobe Desktop-Apps.
And in case it matters, Acrobat Version is X.
Thanks,
Patrick
Copy link to clipboard
Copied
Hi try67,
your solution works like a charm, only had to change the following:
var ocgArray = this.getOCGs();
to
var ocgArray = $doc.getOCGs();
Thank you very much for your help, best regards,
Patrick
Find more inspiration, events, and resources on the new Adobe Community
Explore Now