Skip to main content
Participant
November 28, 2020
Answered

Multilanguage pdf with language selector buttons to toggle layer visibility

  • November 28, 2020
  • 1 reply
  • 4354 views

Hello,

I created a presentation in indesign, which has text in 4 languages. Each language's text is in a different layer: EN, FR, DE, LU. The graphics and other fixed things are in a fifth layer called Fixed. Following a tutorial, I exported the doc from indesign as layered PDF, then in Acrobat Pro I used the "set layer visibility" action making for each button the layer of the corresponding language visible. Unfortunately, this seems to work only for PDF's opened in Adobe Acrobat (Reader). If the document is opened in any other PDF viewer, the buttons have no action. Is there another way to solve this, to work on other PDF viewers too? I read about another way, of javascript using OCGs, but I don't know how to script this. Could you be so kind to help with it?

Thanks a lot!

This topic has been closed for replies.
Correct answer try67

It's highly unlikely it will work using JS if it didn't work using the built-in commands, but you can test it.

For example, this code will toggle the EN layer or or off with each execution:

 

var ocgs = this.getOCGs();
for (var i in ocgs) {
	if (ocgs[i].name=="EN") {
		ocgs[i].state = !ocgs[i].state;
		break;
	}
}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 28, 2020

It's highly unlikely it will work using JS if it didn't work using the built-in commands, but you can test it.

For example, this code will toggle the EN layer or or off with each execution:

 

var ocgs = this.getOCGs();
for (var i in ocgs) {
	if (ocgs[i].name=="EN") {
		ocgs[i].state = !ocgs[i].state;
		break;
	}
}
Participant
November 28, 2020

This one works great. Now I only have to try transforming the script from toggle to exact states: button EN to make layer EN visible and all other three invisible, button DE to make DE visible and all other three invisible, etc. 

try67
Community Expert
Community Expert
November 28, 2020

Surprising, but good to hear! The adjustment is not difficult. For example, this code will show the EN and FIXED layers and hide all others:

 

var ocgs = this.getOCGs();
for (var i in ocgs) {
	ocgs[i].state = (ocgs[i].name=="EN" || ocgs[i].name=="FIXED");
}