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

Table of content page link action to be changed to the corresponding page

Participant ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

Hi All, 

I have a PDF containing the Table of Contents page. Although I have successfully generated a link, it directs to page 1. Is it feasible to modify the link action (Go to page in this document) to the corresponding page using Javascript? Kindly refer to the screenshot provided for further clarification.

 

Magendravarad28403894r8lu_0-1720117547902.png

 

TOPICS
JavaScript , PDF

Views

146

Translate

Translate

Report

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

correct answers 1 Correct answer

Enthusiast , Jul 04, 2024 Jul 04, 2024

I just tested it and looks like the links are numbered in reverse order of creation, so I reversed the loop and it worked.  Run the following script in the console:

 

var cb=this.getPageBox("Crop",0);
var lnks=this.getLinks(0,cb);
for(var i=lnks.length-1;i>-1;i--)
{
var rtn=app.response("Page:");
if(rtn)
{lnks[i].setAction('this.pageNum='+Number(rtn-1))}
}

 

Enter the actual page numbers in the popups for the links in order.  The 0's in the first 2 lines are for page one.  Change them for each TOC page.

Votes

Translate

Translate
Enthusiast ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

In the Actions Tab, select and delete "Go to a page in this document", then select "Run a JavaScript" from the dropdown, then enter this script:

this.pageNum=499;

This script will link to page 500 as page numbers are zero based.  Change the page number accordingly.

Maybe I misunderstood your question.  Are you trying use a script to modify which page number it points to?  In that case you can use the setAction method for the link, but you can't modify "Go to a page in this document", you can only add a script like the one I mentioned above.  Getting the links with a script is complicated because you have to search a specific area of the page and it returns an array of links.  Using transparent form field buttons is a lot easier.

Votes

Translate

Translate

Report

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
Participant ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

Thank you for your reply, However I have more than 10 pages of TOC and to edit each link action it will take more time to complete. Any javascript  to change the page number will help a lot. 

 

Magendravarad28403894r8lu_0-1720120608013.png

 

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

Please re-read my post as I edited it before I received your response.  I don't know if this will help you, but if your document is bookmarked, I created a (paid for) Clickable TOC Tool that automatically creates the TOC from bookmarks.

Votes

Translate

Translate

Report

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
Participant ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

Thank you so much!!! I will try the setaction method. 

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

I would suggest looping through all the links on each TOC page in the console and popping an app.response for each link where you can key in the page number and pass it to the setAction script.  No guarantee the links will display in order but it's worth a shot.

Votes

Translate

Translate

Report

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
Participant ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

I am really sorry, I am not that good at scripting, I am still in learining stage and can you please explain me little more or any Javascript for example. 

 

 

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

See my reply below.

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

I just tested it and looks like the links are numbered in reverse order of creation, so I reversed the loop and it worked.  Run the following script in the console:

 

var cb=this.getPageBox("Crop",0);
var lnks=this.getLinks(0,cb);
for(var i=lnks.length-1;i>-1;i--)
{
var rtn=app.response("Page:");
if(rtn)
{lnks[i].setAction('this.pageNum='+Number(rtn-1))}
}

 

Enter the actual page numbers in the popups for the links in order.  The 0's in the first 2 lines are for page one.  Change them for each TOC page.

Votes

Translate

Translate

Report

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
Participant ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

LATEST

Thank you so much, It works perfectly. 

Votes

Translate

Translate

Report

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