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

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

Participant ,
Jul 04, 2024 Jul 04, 2024

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
1.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
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.

View solution in original post

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

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.

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

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

 

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

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.

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

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

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

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.

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

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. 

 

 

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

See my reply below.

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 ,
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.

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

Thank you so much, It works perfectly. 

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