A hyperlink can be added to a document e.g. by selecting the PDF-Tool "Link Annotation", with the tool drawing a box around the text that shall be linked, double clicking into the box, choose "External Web-Link", then enter the URL as destination. Can we do this from a script? Apparently it is necessary to draw a frame around the text, then call setURIAnnotation for this frame. So the question seems to be really: Given a textframe and some words in the text, how can I determine the x,y,w,h needed to create the smallest frame in which the words are contained (the bounding box)?
Having the hyperlink associated with a frame instead of with the text is problematic anyhow. Consider what happens if you change the text, e.g. put a newline into it. This is perhaps due to PDF? In this way, adding hyperlinks would have to be the very last thing you do to the document before exporting it.