These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

What is the Javascript for flattening all visible layers in a PDF?

kilmanjaro
Registered: Mar 13 2009
Posts: 26
Answered

What is the Javascript for flattening all visible layers in a PDF?

I am creating a button that will hopefully flatten all visible layers in a PDF form I am developing... is this possible?

It is a multi-level document, that certain layers are displayed when a user clicks on particular buttons... once the form is filled out, I would like to flatten all visible layers in the PDF with a button action...

- K

My Product Information:
Acrobat Pro 8.0, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you are talking about OCGs, then unfortunately, there isn't a direct way to flatten the layers using Acrobat JavaScript. As far as I know, the menu items aren't even available. There are some tricks you can play, like importing the PDF page into a button image. But this is not a methology that is suitable for users on Reader. Basically there isn't a way. The best you can do is to set the "initState" and block further changes, so that the layer states are locked in.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

kilmanjaro
Registered: Mar 13 2009
Posts: 26
Thanks Thom!

Yeah OCGs is what I am trying to control...

Bummer.... how would I perform the initState?

Maybe I can give that a try to see what it does...?


Thanks!

Kevin
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
"initState" is a property of the OCG Object in Acrobat JavaScript. You can set this property and it is saved with the PDF. Basically you are just telling acrobat whether or not to turn the OCG on when the file is opened.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

kilmanjaro
Registered: Mar 13 2009
Posts: 26
oh, I see... thanks Thom,

It is possible to assign an initState for an individual layer (OCG) based on the clicking of a Button?

What is the actual script for setting the initState for an OCG, for example a layer titled "sample" to in a display state upon initial view?


Sorry so many questions... : )


Kevin
kilmanjaro
Registered: Mar 13 2009
Posts: 26
Is this correct?

sample.initState = true;


is there any other syntax needed to make this a functional Javascript?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I wrote an article on this topic:

http://www.acrobatusers.com/tutorials/2006/create_use_layers

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

kilmanjaro
Registered: Mar 13 2009
Posts: 26
I'll read through the tutorial... will let you know if any questions come up.

Thank you for your help Thom. I really appreciate it!