Forum


Replies: 4   Views: 704
Converting html to word, heading tags are automatically set to bold in docx file
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 joegraisbery  · 09-12-2022 - 18:49

i am facing issue in converting html to word. when i convert html to word docx all heading tags are automatically set to bold in converted docx file. any one can help me to solve this issue

Posted by admin  · 09-12-2022 - 18:54

Hello,

We recommend you read the following documentation pages:

There's no issue when transforming HTML. The default CSS styles (templates/html.css file) used by phpdocx apply bold style to heading tags and other default styles.

If you don't want to apply to some default style (such as bold in HTML heading tags) you can set new styles when transforming HTML. For example:

$html = '
<style>
h1, h2, h3, h4, h5, h6 {
    font-weight: normal;
}
</style>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
';
$docx->embedHTML($html);

Regards.

Posted by joegraisbery  · 10-12-2022 - 06:35

its working thanks

Posted by joegraisbery  · 10-12-2022 - 06:37

i am facing another issue in generated docx file when i copy content from generated docx file and paste it into ckeditor then headings are not work as h1,h2 etc.

Posted by admin  · 10-12-2022 - 08:51

Hello,

Please note this is not a phpdocx question but from the WYSIWYG or the settings you are using. We recommend you read the WYSIWYG documentation.

If the WYSIWYG or settings you are using require using specific custom paragraph style names applied to headings, you can set them with phpdocx easily. On Working with headings using PHP methods and HTML contents you can read more information about this.

Regards.