Skip to main content
Charu Rajput
Community Expert
Community Expert
October 10, 2021
Question

How to add link to the search text/selected text

  • October 10, 2021
  • 3 replies
  • 1328 views

Hi,

I am new to acrobat scripting, and trying to add links to the text.

So here is what I am doing

1. Searching text (anything name, may be number)

2. Now I want to add the link to the search text via javascript.

 

I am stuck at point 2.

I know one method exists addLink, but it takes parameter as page number and coordinates. So how I can add the link to the search text. Any guidance will be helpful.

 

I am referening the Javascript reference for acrobat 

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
October 11, 2021

OK, I didn't understand.

 

You can use the "Find and Redact" feature to detect all phone numbers, but I don't know how to do with JavaScript to turn Redact's markers into hyperlinks.

 

 

Thank you once again to Adobe which offers us a dark interface with illegible dark texts !

😉

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
Community Expert
October 11, 2021

Looks like you want to create a summary, right?

Acrobate du PDF, InDesigner et Photoshopographe
Charu Rajput
Community Expert
Community Expert
October 11, 2021

@JR Boulay 

I don't know what exactly mean summary here.

but here is what I am doing searching phone number and adding linking to it so that when someone click on it will open default app to call.

Best regards
Charu Rajput
Community Expert
Community Expert
October 10, 2021

To add more,

I have figure it out few things as well, the method getPageNthWordQuads helps to get the quads of the words, but at some times I am unable to pass correct word index to this method. because if my word is like

345-675-8765, then I get total numbe of word count as 3 but it is visisble as one word. So what index number should be passed to getPageNthWordQuads to create link on complete text.

 

I hope I am able to explain my problem clearly.

 

Best regards
try67
Community Expert
Community Expert
October 11, 2021

A hyphen is a word separator in PDF files, so "123-456" will be considered as two words, with two sets of quads. If you want to treat them as a single string you will have to merge those quads yourself, before converting them into a rect and adding a link over them. This is not as simple as it might sound, though.

What if the second part of the text is on another line? You won't be able to cover both words with a single rectangular, unless it covers the entire two lines. In that case you'll have to create two separate links over the two parts of the phrase.

Charu Rajput
Community Expert
Community Expert
October 11, 2021

Yes,

That corrects it does not sound simple. But I am looking for the phone format. So, if it is the phone number I can make the regular expression and matches, but the problem is how to merge the quads?
I mean is there any method that exists in the API or jsut an example if I just need to merge 123-456-7865.

Pointing to the right direction will be a great help.

 

Best regards