Copy link to clipboard
Copied
I am trying to write a script where
1. I will highlight some text on the page and run the script
2. The script will display a list of all of the available Hyperlink Text Destinations where the users will select one and the result will be saved into a variable.
3. I then want the script to add in a cross reference AFTER the highlighted text .
4. Then the script would take the originally selected text and the inserted cross reference and apply a Hyperlink to it.
I have most of the parts working except for being able to insert the cross reference AFTER the initally highlighted text. I have some code below but that will REPLACE the highlighted text with the cross reference.
I have tried inserting it at the index position but I think I might have the syntax wrong and I'm not sure if that is a valid destination anyway.
//put in the destination from the selection
var h = doc.hyperlinkTextDestinations.itemByName(myTextDestination);
//Where is the location for the cross reference to be inserted
var t = doc.selection[0];
//What format should the cross reference use
var xRefForm = doc.crossReferenceFormats.item("Page Number");
//Add the values for the destination and type of cross refernce format
var s = doc.crossReferenceSources.add(t, xRefForm);
//create the cross reference
var xref = doc.hyperlinks.add(s, h);
If anyone can point me in the righ direction it would be greatly appreciated!
Thanks
Hi Rory,
according to DOM documentation method add() of crossReferenceSources requires either the text or an insertion point to create the source. Therefore you may try the following:
var s = doc.crossReferenceSources.add(t.insertionPoints[-1], xRefForm);
( Not tested… )
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Rory,
according to DOM documentation method add() of crossReferenceSources requires either the text or an insertion point to create the source. Therefore you may try the following:
var s = doc.crossReferenceSources.add(t.insertionPoints[-1], xRefForm);
( Not tested… )
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Brilliant, thanks for that @Laubender! It works prefectly now.