Skip navigation
dtm-1979
Currently Being Moderated

Adding Scripts to Specific Pages

May 2, 2012 1:01 AM

Tags: #pdf #script #pro #javascript #scripting #acrobat_10_pro

I've been struggling with this one for a little while, so thought I'd see if any one else can come up with a solution.

 

I've been trying to add scripts to specific pages in PDFs.  I usually add one script at the document level that applies actions to all buttons within the document, but I then have to manually add scripts to pages.

 

Is there a way around this that anyone can think of?  Can I simply write an event listener for the Page/Open and Page/Close events?

 

In a nutshell, I'm trying to achieve something like this (using a modified version of the getField function):

 

this.getPage("1").setAction("Open", "Show('layer1');");

this.getPage("1").setAction("Close", "Hide('layer1');");

this.getPage("3").setAction("Open", "Show('layer1');");

this.getPage("3").setAction("Close", "Hide('layer1');");

 

If anyone can assist, I'd greatly appreciate it!  I don't mind adding these scripts manually to a few pages, but it gets a little tedious when everything else is scripted.

 
Replies
  • Currently Being Moderated
    May 2, 2012 1:27 AM   in reply to dtm-1979

    The Document object has no such method as getPage() in Acrobat, so this

    code is invalid.

    There are no event listeners to the Page Open/Page Close actions.

     

    However, it looks like something that can easily done with a loop that

    applies the same scripts to all the relevant pages.

     
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2012 1:45 AM   in reply to dtm-1979

    If you read the documentation of setPageAction(), you've seen that the first parameter is the page number.

    So if you defined which pages you want to apply this script to, you can change that number in a loop.

    Something like this can be executed from the console:

     

    var pages = [ 0,1,2,10]; // These are the pages we want to add the script to

    for (var i in pages) {

          this.setPageAction(pages[i], "Open", "Show('layer1');");

          this.setPageAction(pages[i], "Close", "Hide('layer1');");

    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2012 1:52 AM   in reply to dtm-1979

    Just remember those page numbers are zero-based, so the first page of the file is 0, not 1.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points