Layer visibility based on different OS/ios devices using javascript
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();
