Forum


Replies: 4   Views: 524
Customizewordcontent + embedhtml
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  · 18-10-2022 - 15:52

Hello,

By default DOCXPath and DOCXCustomizer methods select elements that are direct children of the root tag, w:body for the document content.

On https://www.phpdocx.com/documentation/introduction/docxpath and the API pages you can read this same information:

parent (string, main document body as default, allows to set any parent or a specific one)

Main document body as default, allows to set any parent or a specific one. w:body (default), '/' (any parent) or any other specific parent (/w:tbl/, /w:tc/, /w:r/...).

As you are adding the image in a table, you need to query the elements in all parents:

$docx = new CreateDocx();

$html = '<table width="100%"><tr><td><img src="image.png" width="90" height="90"></td></tr></table>';

$docx->embedHTML($html, ['useHTMLExtended' => true]);

$docx->customizeWordContent(['type' => 'image', 'parent' => '/'], ['imageAlign' => 'center']);

$docx->createDocx('output');

Also note that you can add a center align image in a table with embedHTML without using DOCXCustomizer:

$html = '<table width="100%"><tr><td><p style="text-align: center;"><img src="image.png" width="90" height="90"></p></td></tr></table>';

$docx->embedHTML($html);

DOCXCustomizer allows changing styles on-the-fly, but if you are adding new contents the easiest approach is applying the styles to the contents. On the following pages you can find all options  and stylesavailable for each method and tag:

Regards.