Replies: 1   Views: 601
Image hyperlinks in pdf
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by dev@ams  · 26-01-2021 - 11:38

Hi there,

In, we already posted an issue regarding 'clickable' hyperlinks in pdf. This works correctly now, as per your solution.

However, we still experience this issue where we add hyperlinks to images. They are 'clickable' in produced docx documents, but not in LibreOffice's conversion to pdf. Is there a solution for that?

Posted by admin  · 26-01-2021 - 12:21


HTML to DOCX uses w:hyperlink tags when adding links using an a tag, that are supported in all cases by MS Word and many other DOCX readers. But the current version of LibreOffice doesn't support them when using images, and it requires other structure to set a link to an image. This is not a limitation when exporting the DOCX to PDF but from LibreOffice when reading the DOCX (hyperlinks that surround images aren't supported in LibreOffice).

The addImage method uses a structure when adding a link to an image that is compatible with all DOCX readers, including LibreOffice. If you can't use the addImage method because you only can use HTML to DOCX to add the image, using a Premium license you can use HTML Extended to use the custom phpdocx_image tag (instead of <a><img></a>), for example:

$html = '<phpdocx_image data-src="image.png" data-hyperlink=""/>';
$docx->embedHTML($html, array('useHTMLExtended' => true));

and the same structure as calling addImage will be added to the document, so LibreOffice will read the hyperlinks added to the image too. HTML Extended allows setting custom tag names if you don't want to use phpdocx_image.