Preview disables clickable links in PDF files
The problem was in the encoding of the URL. Apparently Preview is more picky about that compared to other pdf viewers such as Adobe.
Also, it turns out to work better if we put the image inside the link
&lt;a ...&gt;
  &lt;img ...&gt;xx&lt;/img&gt;
&lt;/a&gt;