Forum


Replies: 7   Views: 1675
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

Hello,

UPDATE: https://www.phpdocx.com/documentation/cookbook/working-with-headings

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 https://www.phpdocx.com/documentation/cookbook/tables-of-contents 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 (https://www.phpdocx.com/documentation/introduction/html-extended-to-word-PHP):

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

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

$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.

Regards.