Replies: 5   Views: 2757
Creating docx from html with external css
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 anjanesh  · 16-02-2016 - 07:35

Is it possible to convert HTML with external CSS to DOCX ?

require_once 'phpdocx-trial-pro-5.5/classes/';
$docx = new CreateDocx();
$docx->embedHTML($html, array('isFile' => true));

The external CSS would be


Posted by anjanesh  · 16-02-2016 - 09:20

I tried giving :

$docx->importStyles('', 'merge', array('crazyStyle'));

but I get this when running it in CLI :

FATAL - Error while opening the Style Template: please, check the path

Fatal error: Uncaught exception 'Exception' with message 'Error while opening the Style Template: please, check the path' in /home/username/webapps/domain/phpdocx-trial-pro-5.5/classes/ : eval()'d code:55
Stack trace:
#0 /home/username/webapps/domain/phpdocx-trial-pro-5.5/classes/ PhpdocxLogger::logger('Error while ope...', 'fatal')
#1 /home/username/webapps/domain/create-docx-test.php(10): CreateDocx->importStyles('http://www.cssz...', 'merge', Array)
#2 {main}
  thrown in /home/username/webapps/domain/phpdocx-trial-pro-5.5/classes/ : eval()'d code on line 55


Posted by admin  · 16-02-2016 - 10:38


The importStyles method isn't for CSS styles but Word, you need to use the embedHtml method.

About your error, it seems you didn't copy the whole content of the library.


Posted by anjanesh  · 16-02-2016 - 12:15

I tried doing


$docx->embedHTML($html, array('isFile' => true));

$docx->embedHTML("", array('isFile' => true));

but the resultant DOCX file contains only the text.

Posted by admin  · 16-02-2016 - 12:35


As you're using a trial package, please refer to the included examples and the available documentation. As the trial is crypted it can't be debugged.