# Box around raggedright links spanning two lines extends to right margin

I need to use boxed links and ragged right text. The problem is that when a link spans two lines, though the link is broken correctly (when using pdflatex) the box around the linked text extends until the right margin. Consider the following example:

\documentclass{article}
\usepackage[textwidth=45mm]{geometry}

\begin{document}
\raggedright
\href{http://www.ctan.org/}{The Comprehensive TeX Archive Network}
\end{document}

In the output, the link box extends beyond the end of 'TeX' and up to the right margin, thus enclosing some white space. Is there a way to make the box around the link extend only up to the end of the text and not the right margin?

-
Related: Adjust box around hyperref footnote links (Compiling with XeLaTeX actually solves your problem, too.) – Qrrbrbirlbel Nov 6 '12 at 2:23
Manual way: \href{http://www.ctan.org/}{The Comprehensive TeX} \href{http://www.ctan.org/}{Archive Network} – Qrrbrbirlbel Nov 6 '12 at 2:32
@Qrrbrbirlbel: both solutions indeed work, but I was looking for a solution which works a) automatically and b) in pdflatex. – ctef Nov 7 '12 at 14:55

Simplest is just to link each word separately. Probably if necessary one could prevent the acrobat link boxes from drawing the vertical lines between words, but perhaps this is enough?

\documentclass{article}
\usepackage[textwidth=45mm]{geometry}

\makeatletter
\let\oldhref\href
\def\href#1#2{%
\hrrsp#2 \relax}

\def\hrrsp#1 #2{%