This method allows to insert directly HTML (with CSS styles inline or in a separate CSS file) in your Word document. This method support practically all standard HTML tags: links, paragraphs, tables, lists, etcetera and CSS selectors.
$html: HTML to insert into the document

require_once('../../classes/CreateDocx.inc');
$docx = new CreateDocx();
$html= '<p>This will insert the name in the document: <strong>
<span style="font-size:33px;">My name</span></strong></p>';
$docx->addHTML($html);
$docx->createDocx('example_html');
9 Responses
can i used addhtml with addtemplate variable ?
Does it embed HTML or does it convert HTML to dock (content)
how can we add CSS now?
@ sysadmin@duoconsulting.com
use
use [STYLE][/STYLE]
PS: html tags are removed in comments…
How do handle images that are in the HTML? Can you put a replace the image tag with a temporary placeholder vairable in the html, use “AddHTML”, then use “AddTemplateImage”? I have blocks of html that contain lists, paragraphs, br tags and image tags… would like the image tags to works as well. Thank you.
I have addHTML working nicely, however, images referenced with full url paths, will work when those paths are present, but they do not embed the images in the document. So if the image is moved from the url, the documents can not render the image… is there a way to embed an image from the html?
Hello,
The next version of phpdocx pro will include support for MHT files, so you’can add images offline and other content.
Regards.
It would be useful if the comments had dates so there was a way for me to know which version admins comment refer to.