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

Layer visibility based on different OS/ios devices using javascript

New Here ,
Mar 28, 2018 Mar 28, 2018

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(); 

TOPICS
Acrobat SDK and JavaScript , Windows
309
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
Community Expert ,
Mar 28, 2018 Mar 28, 2018

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

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
Community Expert ,
Mar 28, 2018 Mar 28, 2018
LATEST

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).

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