Replies: 7   Views: 1479
How to create heading with formatstyles in embedhtml?
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  · 24-11-2020 - 10:11



Using a Basic, a Trial or an Advanced package, HTML contents can be added to TOC using heading tags (h1, h2...) or a custom paragraph style. On you can read more information about adding contents to TOC.

Adding a header/footer to a DOCX from HTML using a header/footer tag is only available in Premium licenses using HTML Extended (

HTMLExtended::$tagsBlock['header'] = 'addHeader';
HTMLExtended::$tagsBlock['footer'] = 'addFooter';

$html = '
            p {font-style: italic;}
            p.header {font-size: 20px; font-weight: bold;}
            div.footer {font-size: 10px;}
    <header data-type="default">
        <p class="header">
            Custom header <strong>with strong style</strong>
    <p>Lorem ipsum dolor sit amet.</p>
        <div class="footer">
            <table border="1" style="border-collapse: collapse" width="600">
                        <td width="300">Cell A</td>
                        <td width="300"><img src="image.png" width="35" height="35" style="vertical-align: -15px"></p></td>

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

All licenses can also use replaceVariableByHTML to replace contents by HTML in templates and use addHeader/addFooter to add headers/footers with contents such as text, images, tables, HTML and others.