Author Topic: Pdf Layers  (Read 4799 times)

0 Members and 1 Guest are viewing this topic.

Offline SteveH

  • Visitor
  • Posts: 1
  • Karma: 0
Pdf Layers
« 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

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Pdf Layers
« Reply #1 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

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Pdf Layers
« Reply #2 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.

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: Pdf Layers
« Reply #3 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

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Pdf Layers
« Reply #4 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…

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: Pdf Layers
« Reply #5 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.

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Pdf Layers
« Reply #6 on: December 03, 2009, 03:27:08 AM »
cool thanks for the tip…