Skip to main content
Participant
July 4, 2016
Answered

Find Layer with Name "name1" an rename it to "name2" then save PDF

  • July 4, 2016
  • 1 reply
  • 527 views

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 topic has been closed for replies.
Correct answer try67

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.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 4, 2016

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.

Participant
July 4, 2016

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

Participant
July 4, 2016

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