Skip to main content
Participating Frequently
August 20, 2020
Question

Creating a custom button with Javascript

  • August 20, 2020
  • 2 replies
  • 2261 views

Hi everyone, 

 

I'm trying to automate a custom button dedicated to page navigation, it would:

   1. Set up a "mouse up" action to go to a destination at the bottom of my PDF.

   2. Create a second button at the desired page in the PDF, it should reference where the original button is.

 

Right now I've created a "destinations" tool to move to a specific page. However, I would like to set the destination to the newly created button and visa-versa. 

 

My employer struggles with technology and I believe creating simple buttons like this will help with the form creation and navigation. 

 

Here's some of my code:

 

("Buttons" is my array of buttons)

for(var j = 0; j < buttons.length; j++){

  if(buttons[j].name.substring(0, 7) == "FINDING"){

      buttons[j].fillColor = color.blue;

      buttons[j].textColor = color.white;

      buttons[j].textSize = 10;

      buttons[j].textFont = font.Helv;

      if(buttons[j].pageNum == 2){***This has not worked either***

           buttons[j].setAction("MouseUp", this.gotoNamedDest("Ref"));

     }

   }

}

 

 

Thanks for the help in advance. I hope this was clear enough and I would like to know if what I want is actually possible. I've realized Adobe is not the easiest to work with. I'm a web developer and Adobe's limitations are becoming increasingly frustrating. 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
August 20, 2020

- A field object has a page property, not a pageNum property.

- The second parameter of setAction needs to be the code to execute, but in the form of a string, like this:

buttons[j].setAction("MouseUp", "this.gotoNamedDest(\"Ref\")");

Nesa Nurani
Community Expert
Community Expert
August 20, 2020

You can create button and as mouse up event choose "Go to a page" to set page and view.
You can create button to go back to previous page using this code:  app.goBack()
or you can go  to specific button if you use code like this: this.getField("Button name").setFocus();
Hope some of this can help you.