Skip to main content
Participant
March 28, 2018
Question

Layer visibility based on different OS/ios devices using javascript

  • March 28, 2018
  • 2 replies
  • 350 views

Is there a way to control what Acrobat PDF layers are visible based on the particular OS or device the person viewing an Acrobat file is using when it is opened?

I was optimistic when I saw Show/hide layers and fields on doc startup

It seemed to suggest that I may be able to switch off a layer if I wasn't using a Windows or Mac machine, i.e. possibly an iOS device. Having tried other strategies that hadn't worked I thought I'd give it a go.

I modified the javascript from that post to just toggle layers on or off (I wasn't worried about fields) that I had created and exported from InDesign. I added the code below as a 'document javascript'. Like so many other options it seems to work OK on a desktop but not an iOS device which continues to display all layers.

// Get Layer Names   

function findLayers(cName) {  

  var fLayers = this.getOCGs();  

  for (var i = 0; fLayers && i < fLayers.length; i++) {  

    if (fLayers.name == cName) return fLayers

  }  

  return null; 

}  

 

function a_check_Reader_and_OS() { 

  if (app.platform == "WIN" || app.platform == "MAC") { 

   if (app.viewerType == "Reader" || app.viewerType == "Exchange-Pro") {

    findLayers("ios device").state = false; 

    findLayers("desktop").state = true; 

    app.runtimeHighlight = true; 

   }  

   else { 

    findLayers("Master Page").state = true;  

   } 

  } 

  else { // If not running Windows or Mac, just show the Master Page layer

   findLayers("ios device").state = false; 

   findLayers("desktop").state = false; 

   findLayers("Master Page").state = true; 

  }   

}   

run = app.setTimeOut ("a_check_Reader_and_OS()", 1000); //re-run the function to refresh highlighted fields 

a_check_Reader_and_OS(); 

This topic has been closed for replies.

2 replies

Karl Heinz  Kremer
Community Expert
Community Expert
March 28, 2018

I am also not aware of any mobile PDF viewers that supports layers (or the JavaScript to show and hide them). What you can do is to arrange your layers in such a way that you get the correct look for a system that does not support layers, and then use JavaScript to turn on and off those layers that you want to show when viewing on a Mac or the Windows version of Adobe Acrobat or the free Reader. Keep in mind that when you use non-Adobe software, all bets are off (this also applies e.g. to displaying these PDF files in most web browsers).

try67
Community Expert
Community Expert
March 28, 2018

I don't believe that any PDF app for mobile devices supports layers.