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.
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.
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.
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.
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.
Copy link to clipboard
Copied
Thank you so much!!! I will try the setaction method.
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.
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.
Copy link to clipboard
Copied
See my reply below.
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.
Copy link to clipboard
Copied
Thank you so much, It works perfectly.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now