Forum


Replies: 1   Views: 1252
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 admin  · 26-01-2021 - 12:21

Hello,

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="http://www.google.es"/>';
$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.

Regards.