Forum


Replies: 8   Views: 4143
Embed html and page-break-inside property
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 tutotours  · 28-08-2017 - 10:15

Hello !

 

I want to use page-break-inside CSS property. I use embedHTML method. This property is working as intended wih <p> but not with divs. With divs, it has no effect. Why is that ? How can I do to make it work ?

 

I have a Premium licence.

 

Thank you !

Posted by tutotours  · 28-08-2017 - 17:56

I tried it with no success. I think it's because I have an ordered list in this div. Do you have a way to make page-break-inside work with a div with an ol element. I tried to ut the ol element inside a paragraph but it doesn't work either.

Posted by admin  · 28-08-2017 - 19:00

Hello,

MS Word doesn't have a tag for lists. Lists are paragraphs but with an special numbering style; so when you add a list, the conversion from HTML to MS Word included in phpdocx generates a paragraph for each list item (but there's no root element that wraps all items of the list, as each item has its own w:p tag and a numbering style).

UPDATE: https://www.phpdocx.com/documentation/snippets/prevent-break-table-HTML

Regards.

Posted by tutotours  · 30-08-2017 - 19:18

Hello,

 

If I understand your answer correctly, I could use page-break-inside with <ol> or <ul> element with the code sample you gave me. But I want page-break-inside to apply on something like :

<p>
   Some text
   <ol>
       <li>...</li>
       <li>...</li>
   </ol>
</p>

 

 

I also didn't understand where to put the first code sample.

Posted by tutotours  · 09-09-2017 - 17:22

I tried your solution.

I added the lines in HTML2WordML.inc and I made an HTML like this that's repeated to test the behavior : 

<p style="page-break-inside: avoid;">
    Some text
    <ol>
        <li style="page-break-inside:avoid;">Item 1</li>
        <li style="page-break-inside:avoid;">Item 2</li>
    </ol>
</p>

 

I still have some page-breaks between li elements or between text and ol element.

Posted by admin  · 11-09-2017 - 08:34

Hello,

We have checked it and it's working fine after applying the previous lines to HTML2WordML.inc. But due to how MS Word works, you need to add the page-break-after style to accomplish what you need.

This is a simple sample that illustrates how to do it (you can use inline styles or a external CSS):

$html = '
<p style="page-break-inside: avoid;">
   <p style="page-break-inside: avoid; page-break-after: avoid;">Some text</p>
   <ol>
       <li style="page-break-inside: avoid; page-break-after: avoid;">Item 1</li>
       <li style="page-break-inside: avoid; page-break-after: avoid;">Item 2</li>
   </ol>
</p>
';
$docx->embedHTML($html);

If you open the DOCX with MS Word, you can see that the paragraph and lists have the keep with next option enabled and act as a 'block' for the content page.

On the snippets section (https://www.phpdocx.com/documentation/snippets/) you can find some samples about this same question.

Regards.

Posted by tutotours  · 11-09-2017 - 20:42

Hello,

It's working now. I have another problem with lists but I'll open a new topic. 

Thank you !