Forum


Replies: 1   Views: 919
Using embedhtml wordstyles with images
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 dannyguest  · 03-12-2021 - 11:45

We are using EmbedHTML to display a image in a report which is working fine. As an additional piece of functionality we now want to optionally set and outer border to the image. We have created a WordStyle and are trying to apply it to the image.

private function generate_chart_fragment($docx,$image){
    $chart_fragment = new WordFragment($docx, 'document');
    $chart_fragment->embedHTML('<img src="' . $image . '" id="chartborder">',array('wordStyles'=>array('#chartborder'=>'ChartWithBorder')));
    return $chart_fragment;
}

It appears the wordStyles option is not functioning as we expected.

We have tried adding style="border: 1px solid #000" which did add a border to the image but the top and bottom ones were thinner than the ones on the left and right for some reason. 

Any help would be appreciated.

Posted by admin  · 03-12-2021 - 12:18

Hello,

HTML methods allow applying word styles to tables, paragraphs and characters. Each custom style can be applied to the correct contents; for example a custom paragraph style can be applied to paragraphs or headings but can't be applied to images.
On https://www.phpdocx.com/documentation/introduction/html-to-word-PHP (Using native Word formatting with HTML section) is available this same information. In the package you can also find the following sample that illustrates how to use the wordStyles option with paragraphs, tables and characters.

Borders can be added to images using HTML/CSS (https://www.phpdocx.com/htmlapi-documentation/html-standard/insert-image-Word-document-with-HTML). If you are getting a thinner border in top and bottom positions, maybe some content is overlapping it. Please check the following topic that details a very similar question: https://www.phpdocx.com/en/forum/default/topic/2199 ; we recommend adding some spacing/margin to the image or the contents to avoid that overlapping.

Regards.