Skip to main content
saratogacoach
Inspiring
December 25, 2016
Answered

Document Cloud JavaScript not working

  • December 25, 2016
  • 1 reply
  • 595 views

Hi,

Been trying to change layer visibility using script: PDF is created as interactive PDF in InDesign cs6 with 3 layers, with the first set in InDesign to visible, second layer default set in InDesign to not visible, third layer which in InDesign when exporting as interactive PDF automatically is exported with no control over it (Guides and Grids), can in Acrobat Pro DC be set to not visible. Using a script from Try67 from this forum (Can I remove a layer using Javascript? ) I modify to name the second layer "background" to become visible instead of the default first layer, and all else to be hidden.

var ocgs = this.getOCGs();

for (var i in ocgs) {

    if (ocgs.name=="background")

        ocgs.state = true;

    else ocgs.state = false;

}

If I open the PDF on a Windows desktop, works perfectly. Upon opening, the first layer and third layers are not visible, and the second layer ("background") is visible.

The problem:

If I upload same PDF to Adobe Document Cloud, run it online as web preview, doesn't run correctly like on the desktop: first layer stays visible and other layers remain hidden.

Any way to get this JavaScript to work in Document Cloud to allow the user viewing the PDF in the cloud (not downloaded)?

Thank you for you help.

This topic has been closed for replies.
Correct answer Joel Geraci

No. It's just not possible.

I don't know of any browser-based PDF viewers that can process full Acrobat JavaScript API. Adobe Reader on mobile doesn't even have the objects and methods you'd need to work with layers.

That code will only work in a desktop viewer or a browser capable of loading Adobe Reader as a plug-in... and these days, pretty much leaves you with IE, not even Edge.

J-

1 reply

Joel Geraci
Community Expert
Joel GeraciCommunity ExpertCorrect answer
Community Expert
December 25, 2016

No. It's just not possible.

I don't know of any browser-based PDF viewers that can process full Acrobat JavaScript API. Adobe Reader on mobile doesn't even have the objects and methods you'd need to work with layers.

That code will only work in a desktop viewer or a browser capable of loading Adobe Reader as a plug-in... and these days, pretty much leaves you with IE, not even Edge.

J-

saratogacoach
Inspiring
December 25, 2016

Thanks, Joel.