Forum


Replies: 2   Views: 1348
Embedhtml renders h* with bold character style
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 admin  · 03-04-2021 - 12:01

Hello,

Heading tags apply a bold style because this style is included in the default CSS template when adding HTML (as any other browser or library that work with HTML, phpdocx has a default CSS template to handle styles correctly):

h1, h2, h3, h4, h5, h6 {
  display: block;
  font-weight: bold;
}

You can find this default CSS in the following path in the package: templates/html.css. 

You can customize this template if you don't want to apply bold styles to heading tags, or change it when importing HTML/CSS applying a custom style as CSS allows:

h1, h2, h3, h4, h5, h6 {
  font-weight: normal;
}

You can apply it by changing the base template (html.css) to do a global change, when calling HTML methods such as embedHTML:

$html = '<style>h1, h2, h3, h4, h5, h6 {font-weight: normal;}</style>';
$html .= '<h1>An embedHTML() example</h1>';

to only change it for that specific HTML, or with addBaseCSS available in HTML Extended (https://www.phpdocx.com/documentation/introduction/html-extended-to-word-PHP) to apply the styles to all contents added using embedHTML/replaceVariableByHTML in the same script.

A few specific styles are always added although the strictWordStyles option is set to true to guarantee the correct internal workflow of the conversion and compatiblity reasons with previous versions of phpdocx.

Regards.