Forum


Replies: 6   Views: 420
Widowcontrol in combination with html inserted text
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  · 19-10-2023 - 13:54

Hello,

You don't need to break the HTML into smaller pieces. You can apply supported CSS styles as needed.
If you don't want to change the HTML to be transformed, the easiest approach is using CSS styles. Setting custom styles may require adding new class to select the contents to be applied (HTML tags can also be used to set custom styles).

Please note that as default, HTML to DOCX sets widowControl as true.
For example, if you run:

$html = '<p>Text content</p>';
$docx->embedHTML($html);

The widowControl tag is enabled:

<w:p>
    <w:pPr>
        <w:widowControl w:val="on"/>
        <w:pBdr/>
        <w:spacing w:after="240" w:before="240" w:line="240" w:lineRule="auto"/>
        <w:ind w:left="0" w:right="0"/>
        <w:jc w:val="left"/>
    </w:pPr>
    <w:r>
        <w:rPr>
            <w:color w:val="000000"/>
            <w:sz w:val="24"/>
            <w:szCs w:val="24"/>
        </w:rPr>
        <w:t xml:space="preserve">Text content</w:t>
    </w:r>
</w:p>

If you open the DOCX with MS Word you can check (right click on the paragraph and "Line and Page Breaks" option) that the Widow/Orphan control option is enabled. You can disable widowControl using the page-break-before style (https://www.phpdocx.com/htmlapi-documentation/html-standard/insert-paragraph-text-Word-document-with-HTML):

$html = '<style>p{page-break-before: avoid;}</style><p>Text content</p>';
$docx->embedHTML($html);

After purchasing a license we can provide further support about this and other questions. After you have purchased a license, do not hesitate to send a message to contact[at]phpdocx with a HTML sample you are using so we can help you.

Regards.