Skip to main content
New Participant
March 26, 2020
Answered

Hyperlink InDesign Script Javascript

  • March 26, 2020
  • 3 replies
  • 5085 views

I want to attach a hyperlink to the currently selected pageItem — app.selection[0].

My selected pageItem will sometimes be an image, sometimes be text.

When the user clicks on the pageItem in an interactive PDF I want it to open the URL say "adobe.com"

 

I can't find any resources that explains how to create hyperlinks and attach them to pageItems.

I need help. Thanks!

This topic has been closed for replies.
Correct answer

Thanks peeps, those two resources combined a whole bunch of trial and error was an enough to get me over the hump. (Changed my name btw)

 

Solution:

 

//Converts selected pageItem to a hyperlink

var myPageItem = app.selection[0]; //First currently selected pageItem
var myURL = "www.adobe.com"; //Pick any URL

var source = app.documents[0].hyperlinkPageItemSources.add(myPageItem);
var dest = app.documents[0].hyperlinkURLDestinations.add(myURL);

//Add hyperlink to the pageItem
app.documents[0].hyperlinks.add(source, dest, {name:myURL}) 
//Name can be anything you want, it can also be used to find the item with the "itemByName()" function

 

 

3 replies

Correct answer
March 27, 2020

Thanks peeps, those two resources combined a whole bunch of trial and error was an enough to get me over the hump. (Changed my name btw)

 

Solution:

 

//Converts selected pageItem to a hyperlink

var myPageItem = app.selection[0]; //First currently selected pageItem
var myURL = "www.adobe.com"; //Pick any URL

var source = app.documents[0].hyperlinkPageItemSources.add(myPageItem);
var dest = app.documents[0].hyperlinkURLDestinations.add(myURL);

//Add hyperlink to the pageItem
app.documents[0].hyperlinks.add(source, dest, {name:myURL}) 
//Name can be anything you want, it can also be used to find the item with the "itemByName()" function

 

 

spyle
Inspiring
March 27, 2020

For a full reference of what you can do with hyperlinks, see this site: http://jongware.mit.edu/idcs6js/index_Hyperlinks%20Suite.html

 

Specifically, the hyperlinks.add method should do what you need: http://jongware.mit.edu/idcs6js/pc_Hyperlinks.html#add

Brainiac
March 27, 2020

Hello lynddonn84836010,

 

See this post by Manan Joshi. Seems to be excaltly what you're looking for, if not it should get you pointed in the right direction.

 

https://community.adobe.com/t5/indesign/how-to-convert-text-selection-into-hyperlink/td-p/10442568?page=1

 

Regards,

Mike