September 05, 2010, 08:11:22 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Pdf Layers  (Read 407 times)
0 Members and 1 Guest are viewing this topic.
SteveH
Visitor


Karma: 0
Offline Offline

Posts: 1


« on: November 30, 2009, 01: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

Logged
larsen67
Sr. Member
****

Karma: 10
Offline Offline

Gender: Male
Posts: 457



« Reply #1 on: November 30, 2009, 07: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


Logged
larsen67
Sr. Member
****

Karma: 10
Offline Offline

Gender: Male
Posts: 457



« Reply #2 on: November 30, 2009, 07: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.

Logged
cdms
Jr. Member
**

Karma: 6
Offline Offline

Gender: Male
Posts: 84


« Reply #3 on: December 02, 2009, 06: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. Tongue

Logged
larsen67
Sr. Member
****

Karma: 10
Offline Offline

Gender: Male
Posts: 457



« Reply #4 on: December 02, 2009, 07: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…

Logged
cdms
Jr. Member
**

Karma: 6
Offline Offline

Gender: Male
Posts: 84


« Reply #5 on: December 03, 2009, 12: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.

Logged
larsen67
Sr. Member
****

Karma: 10
Offline Offline

Gender: Male
Posts: 457



« Reply #6 on: December 03, 2009, 01:27:08 AM »

cool thanks for the tip…

Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!