Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jul 04, 2016 Jul 04, 2016

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

TOPICS
Acrobat SDK and JavaScript
493
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 04, 2016 Jul 04, 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.

Translate
Community Expert ,
Jul 04, 2016 Jul 04, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 04, 2016 Jul 04, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 04, 2016 Jul 04, 2016
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines