Publi-Script Forums

Publishing Applications => Acrobat support => Topic started by: SteveH on November 30, 2009, 03:55:39 AM

Title: Pdf Layers
Post by: SteveH on November 30, 2009, 03:55:39 AM
HELP::
I need to write a javascript to turn a specific layer off within a pdf file. The layer name is always the same. Is there anyone who can help me do this? Thanks
Title: Re: Pdf Layers
Post by: larsen67 on November 30, 2009, 09:25:48 AM
var docOCGs = this.getOCGs();

for (var i = 0; i < docOCGs.length; i++) {
   if (docOCGs.name == "Marks" && docOCGs.state == true) docOCGs.state = false;
}

This is looking for a layer by name string "Marks" in this case and its state is currently visible
Title: Re: Pdf Layers
Post by: larsen67 on November 30, 2009, 09:53:15 AM
ooops it would appear that this forum does not like JavaScript's square brackets?

In the fourth line it should be 'docOCGs' then 'open square bracket' then 'i' then 'closing square bracket' then dot the rest in 3 places…

Sorry about that.
Title: Re: Pdf Layers
Post by: cdms on December 02, 2009, 08:27:17 AM
Hi Steve, welcome to the forum. I told you someone here would have an answer for you. (Thanks larsen)
In case anyone is not sure the script needs to look like this.

var docOCGs = this.getOCGs();

for (var i = 0; i < docOCGs.length; i++) {
   if (docOCGs[i].name == "Marks" && docOCGs[i].state == true) docOCGs[i].state = false;
}

Your [s do not need to be blue. :P
Title: Re: Pdf Layers
Post by: larsen67 on December 02, 2009, 09:36:51 AM
Layers btw are 'optional content groups' in PDF you should have piece of cake bottom left of your file if it has these.

cdms, how u get them brackets to post here? I did not have the time to try work this one out…
Title: Re: Pdf Layers
Post by: cdms on December 03, 2009, 02:34:00 AM
Most forums will tend to strip out paired [s especially where it sees something like [ i ] (without the spaces). This helps stop people posting a malicious bit of javascript into the middle of an html page. If you break it up with spaces or color tags then it is not javascript anymore and will be left alone.
Title: Re: Pdf Layers
Post by: larsen67 on December 03, 2009, 03:27:08 AM
cool thanks for the tip…