Forum


Replies: 1   Views: 572
Phpdocx 5.5: css style's style code inserted as text in the docx file all of a sudden
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 davelavinsky  · 17-06-2021 - 16:00

I didn't have this issue before. It was brought to my attention only recently, so I don't know for how long this issue remained online. No code was changed / modified in the last year or so.

Using phpdocx-corporate-5.5, PHP 7.4.18

$style = "<style type='text/css'>
h1 { page-break-before:always; }
h1:first-child { page-break-before:avoid; }
p.sample { font-weight:bold; background-color:#FFFF00; }
p.empty { color:#fff; background-color:blue; }

.tbl-summary { border-collapse:collapse; font-size:12px; }
.tbl-summary thead tr th { font-weight:bold; }
.tbl-summary thead tr th,
.tbl-summary thead tr td,
.tbl-summary tbody tr td
{
    border:1px solid #000000;
    padding:2px;
    text-align:center;
    width:100px;
}
.tbl-summary tbody tr td:first-child
{
    text-align:left;        
}
</style>";

$html = $style;

$html .= "<p class='sample'>Test</p>";

.
.
.
$docx->embedHTML($html);

All the html code gets displayed properly. But this style code is showing as text in the docx. It's not getting inserted as a CSS style.

h1 { page-break-before:always; } h1:first-child { page-break-before:avoid; } p.sample { font-weight:bold; background-color:#FFFF00; } p.empty { color:#fff; background-color:blue; } .tbl-summary { border-collapse:collapse; font-size:12px; } .tbl-summary thead tr th { font-weight:bold; } .tbl-summary thead tr th, .tbl-summary thead tr td, .tbl-summary tbody tr td { border:1px solid #000000; padding:2px; text-align:center; width:100px; } .tbl-summary tbody tr td:first-child { text-align:left; } 

 

Posted by admin  · 17-06-2021 - 16:07

Hello,

You need to enable the PHP Tidy extension; it seems you didn't enable this required extension to transform HTML to DOCX when you upgraded your PHP version. This requirement is explained on the documentation pages: https://www.phpdocx.com/documentation/cookbook/convert-html-to-word

 Warning
If you haven't installed the Tidy extension, errors may ocurr, like appearing the CSS styles in the document, import with errors the HTML or not displaying accents and other non ASCII characters.

Also please note that phpdocx is compatible with PHP 7.4 since the release of phpdocx 9.5 (https://www.phpdocx.com/news/post/phpdocx-v9-5-release-notes/219). Using previous versions of phpdocx with PHP 7.4 is not supported and you can get unexpected errors. We recommend you to upgrade your version of phpdocx to the latest release on MY PHPDOCX page after login.

Regards.