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

Layers etc....

alexpapa
Registered: Nov 25 2008
Posts: 68

Hey everyone,

I have the following requirement:

1) A customer receives a password protected PDF
2) They enter in their password and then get a second dialog saying "to view this you must accept the terms and conditions...etc...etc..."
3) User clicks ok and the PDF is viewable..

my solution to this is to, on the PDF being opened to add a layer with javascript which basically hides the contents of the PDF - if they click cancel, I simply do not remove it...

so my questions are..

1) does anyone have any sample code to add a full page layer in this respect, I have found watermark code, but nothing else so far...
2) can I add layers which span multiple pages?

Thanks for the help

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You cannot add a layer (OCG) to the PDF when it is opened. Don't even think about it. This cannot be done in Reader, and there is always the possibility that JavaScript will be turned off. The OCG has to be there in the first place.

Take a look at this article:
http://www.acrobatusers.com/tutorials/2006/create_use_layers

And the License Dialog sample file on this page:
http://www.windjack.com/products/acrodialogs.php

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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

IanButtery
Registered: Aug 16 2008
Posts: 5
Hi,

I have a multi-layered pdf with layers named "Base" "layer1", "layer2", "layer3", "layer4". I wanted to turn off all layers except "Base" and "layer1" and then re-save the file. Could anyone point me in the right direction of a JavaScript to do this please.
Thanks in advance
Ian.

Business Consultant.
Applescript and Javascript development for PDF workflow solutions.
Prepress Project Management.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Take a look at this article:
http://www.acrobatusers.com/tutorials/2 … 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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

IanButtery
Registered: Aug 16 2008
Posts: 5
Thanks Thom,
I've managed to identify the layers I want to use in the final PDF using your excellent documentation, but am unsure of how to merge these into one layer ie., "Base" and "Layer1" into one layer, then resave the PDF file.
Could you help please?
Thanks
Ian

Business Consultant.
Applescript and Javascript development for PDF workflow solutions.
Prepress Project Management.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
From JavaScript you cannot merge layers. Too bad, this would be a great feature for automation scripting:( This can only be done from the Layers Panel in Acrobat Professional.

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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

IanButtery
Registered: Aug 16 2008
Posts: 5
Thanks Thom.

I need some guidance then if possible. I can get away with just hiding the layers and not merging, but how do I do this? I've tried the below script

FindOCG("NZ").state = false;
FindOCG("AUS").state = false;
FindOCG("USA").state = false;

But I get a syntax error

Business Consultant.
Applescript and Javascript development for PDF workflow solutions.
Prepress Project Management.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What specifically is reported for the Syntax error? The code in your post is correct. Is the "FindOCG()" function defined? Is the error inside this function?

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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

clm
Registered: Feb 18 2011
Posts: 1
Is it still the case, that you can't use JavaScript to merge layers? I've seen this code around:

sourcename.name = targetLayer.name;
sourcename.initState = targetLayer.initState;
sourcename.intent = targetLayer.intent;
sourcename.locked = targetLayer.locked;
sourcename.state = targetLayer.state;

but when I actually get it to run, I end up with a bunch of layers all having the same name, they're not actually merged.


Can I do this with JavaScript?

UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
CLM:

OCGs cannot be created, merged or deleted with JavaScript in Acrobat X or any previous version. You can import and merge layers using the UI tools in Acrobat Pro, but can only delete and rearrange content within layers using plugins such as ARTS PDF Aerialist.

All your script does is copy the properties of one OCG to another, but they stay as two independent layers.