I am building an InDesign application that reads a document composed by our design staff that looks for text that qualifies as an intended hyperlink to our web site. The application objective is to recognize these "links" and convert them to actual InDesign hypertext links so PDFs rendered by InDesign have functional links.
These "links" are imbedded in sometimes long paragraphs.
At this point (the hurdle) I am able to find the intended links and create the InDesign links, but only to the complete paragraph, not the specific text in the paragraph that should have the active link applied (the HyperlinkTextSource).
This code applies the HyperlinkTextSource to the whole paragraph...
Set oHyperlinkTextSource = oDoc.HyperlinkTextSources.Add(oPara.Texts.Item(1))
I have been working with the ItemByRange function to try to pass just the appropriate substring of the paragraph, but have had no success.
This is possible from the desktop, select a part of a paragraph with the text tool, then right mouse click to Interactive/NewHyperlink and the New Hyperlink dialog box opens with the Name: = to the selected text. This link behaves the way the automated link creation is desired.
For starters, can anyone confirm that what I am trying to do is possible? If yes, then how.
The Object Browser defines HyperlinkTextSources.Add as...
Function Add(Source As Text) As HyperlinkTextSource
Member of InDesign.HyperlinkTextSources
Creates a new hyperlink text source. / Return value: The new source. / Source: The text or insertion point to hyperlink.
When I usethe immediate window...
Is a String type the same as the (Source as Text) required by the .Add function? It appears not since I get a "Type Mismatch"
Thanks for any assistance on this topic.
The .contents of a Text are a String, and refers just to its characters. However, a hyperlink needs to be linked to a physical position on a formatted page -- so it needs Text.
Try with oPara.Texts.Item(1).characters.ItemByRange(lngLinkStart, lngLinkEnd) as the Text parameter, not its contents.
Thank you for the response. I now understand the difference. I believed it was necessary to have the HyperlinkTextSource be "anchored" to the specific part of the paragraph, much like selecting the characters on the desktop.
Set oHyperlinkTextSource = oDoc.HyperlinkTextSources.Add(oPara.Texts.Item(1).Characters.ItemByRange(lngLinkStart, lngLinkEnd))
VB responds with:
Run-time error '13'; Type Mismatch
I tested with:
And it responded with:
I think this is on the right track, but the .Add wants Text.
Information on any functions or methods that would acheive the desired result would be appreciated.