Forum


Replies: 5   Views: 4956
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 ?

<?php
require_once 'phpdocx-trial-pro-5.5/classes/CreateDocx.inc';
$docx = new CreateDocx();
$html='http://www.csszengarden.com/215/';
$docx->embedHTML($html, array('isFile' => true));
$docx->createDocx('csszengarden-215');
?>

The external CSS would be http://www.csszengarden.com/215/215.css?v=8may2013

Thanks

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

I tried giving :

$docx->importStyles('http://www.csszengarden.com/215/215.css?v=8may2013', '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/AutoLoader.inc(62) : eval()'d code:55
Stack trace:
#0 /home/username/webapps/domain/phpdocx-trial-pro-5.5/classes/CreateDocx.inc(4013): 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/AutoLoader.inc(62) : eval()'d code on line 55

 

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

Hello,

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.

Regards.

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

I tried doing

$html='http://www.csszengarden.com/215/';

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

$docx->embedHTML("http://www.csszengarden.com/215/215.css?v=8may2013", array('isFile' => true));

but the resultant DOCX file contains only the text.

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

Hello,

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.

Regards.