Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Use Acrobat Javascript to add button field with action goto a page view

Guest
Aug 06, 2017 Aug 06, 2017

I am trying to use Javascript to automatically insert buttons in a document that link to other pages within the document. In order to place the button I use this.addfield, however cant find the syntax for the setAction statement.

So I then tried to set it to run a javascript making use of cscript with to set this.pageNum = x, however when ever I check the properties of the button the pageNum has been changed to the page the button has been placed on.

What syntax to I need to place a button field onto a page with the selected action going to a page view. Or how do I write the javascript to use this.pageNum to another page in the pdf.

TOPICS
Acrobat SDK and JavaScript , Windows
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2017 Aug 06, 2017

A script can only apply JavaScript-based actions, but the method you described should have worked just fine... Can you maybe share the code you used to create the buttons? It sounds like you have some issues there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2017 Aug 06, 2017

Use something like this:

f.setAction("MouseUp", "this.pageNum = x;");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 06, 2017 Aug 06, 2017

Hi

In the document I have, the sections have page numbering depending on the chapter. So the page number mayl be shown as "N-1" and be "N1" within acrobat. So to generate the page link in the script the letter is put in varWord and the number in linkpage. qQuads comes from another script to give the position for the button.

When tested the correct info is shown from

app.alert(pageRef);

eg. "pageNum = N101"

however when I check the button properties the following script is present:

this.pageNum = N2;

I have tried:

f.setAction("MouseUp", "this.pageNum = " +varWord + linkPage + ";");

which also resulted in a javascript beint added to the button.

function addbutton(varWord, thisWord, thisPage, qQuads, NormalPage)

{

// view page to have button added

    this.pageNum = thisPage;

// work Quads of reference

    var sQuads = qQuads.toString();

    var aQuads = sQuads.split(",");

// get page rect dimensions

    var pgRect=this.getPageBox("Crop", thisPage);

    var fldRect=[];

// apply rect to make button dimension to cover width of page and apply offset fix

    pgRect[0] = 0;

    pgRect[1] = +aQuads[5]-234;

    pgRect[2] = +423;

    pgRect[3] = +aQuads[1]-234;

// set up and get page number to link to

    var linkPageVal=thisWord+1;

    var linkPage = this.getPageNthWord(thisPage, linkPageVal);

// confirm the page number to which the button should link

    var pageRef = "pageNum = " +  varWord + linkPage;

    app.alert(pageRef);

// generate cscript for the button

var cscript = "this.pageNum = " +varWord + linkPage + ";";

// place button field and set parameters

    var f = this.addField("actionField", "button", thisPage, pgRect);

    f.setAction("MouseUp", cscript);

    f.delay = false;

    f.fillColor = color.transparent;

    f.buttonSetCaption("");

    f.borderStyle = border.s;

     f.display = display.visible;

    f.lineWidth = 1;

    f.strokeColor = color.black;

    f.highlight = highlight.o;

    f.delay = false;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2017 Aug 06, 2017

You can't use the page labels for this. You must only use the physical page number. The first page is 0, the second page is 1, etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 06, 2017 Aug 06, 2017

I have adjusted the script to point to the physical page, which I confirm with the app.alert(cscript). However when I check the button properties the pageNum has changed and points to the page with the button on it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 06, 2017 Aug 06, 2017

If I run the process for one button then the script is correct. So assume, as all buttons have the same name that the javascript is modified to the last one declared. I will try giving each button an individual name.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 07, 2017 Aug 07, 2017

I renumbered each button and converted the page label to the absolute page number for it to work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2017 Aug 07, 2017
LATEST

Post your new code, including how you're calling it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines