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

Multilanguage pdf with language selector buttons to toggle layer visibility

Community Beginner ,
Nov 28, 2020 Nov 28, 2020

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!

TOPICS
Edit and convert PDFs , How to , PDF forms
4.3K
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 28, 2020 Nov 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;
	}
}

View solution in original post

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 ,
Nov 28, 2020 Nov 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;
	}
}
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 Beginner ,
Nov 28, 2020 Nov 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. 

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 ,
Nov 28, 2020 Nov 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");
}

 

 

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 Beginner ,
Nov 28, 2020 Nov 28, 2020

Thanks a lot, works great. Only one strange issue: 

I have two documents. One is a simple presentation pdf with text layers for each languages, which works as expected (click on the button, language changes). The second document is an interactive invoice with text fields, some for input some calculated. In Acrobat (Reader) pressing a language button worked. In other readers, I observed that pressing button 1 does nothing, pressing button 2 changed what button 1 should have done, pressing button 3 changed what button 2 should have done. Another observation was that pressing button 1 did nothing, pressing one more time outside the button, anywhere on the page, did the change. So I did another trick, which seems to work: I put the same script both on mouse down and on mouse up for each button. Now pressing each button has immediate effect. While my problem is solved by doubling the script, I am still curious what could cause this in my second document...

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 ,
Nov 29, 2020 Nov 29, 2020

Most of the non-Adobe PDF viewers out there are sub-par and have issues, especially when it comes to form fields and scripts...

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 Beginner ,
Nov 29, 2020 Nov 29, 2020

Another update: although calculations-scripts work on Acrobat for iPad, this layer visibility script doesn't work on iPad. Is this known?

And an off-topic funny thing:

cell 1 - qty    cell2 - unitprice   cell3 - total. I type 3 in qty, the formula in total is:

 

if( this.getField( "qty").value == 0 ) {event.value = "";} 
else {event.value = this.getField("qty").value * 0.7;}

So qty is displaying, logically, 2.100

fallprotec_1-1606661197490.png

If I click on 2.100, it changes to 2.0999 until I click somewhere else, when it comes back to 2.100

fallprotec_0-1606661144356.png

 

I remember a joke, which says:

- If I cut a cake in 3, how many percent has each?

- 33.3%

- If we add the three parts, how many percent will result?

- 99.9%

- Where did we lose 0.1%?

- That's the cake which remains on the knife.

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 ,
Nov 29, 2020 Nov 29, 2020
LATEST

- Yes. Almost no scripts work on mobile devices, either.

 

- This issue is actually a known problem in computer science, called a floating number rounding error.

If you don't want to see the "incorrect" value make the field read-only or use a script to round the result to 2 decimals, like this:

event.value = (this.getField("qty").value * 0.7).toFixed(2);

The latter changes the field's actual value. The former just prevents the user from seeing the longer value.

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