Forum


Replies: 3   Views: 4109
Embedhtml; prevent table/paragraph on page break
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 aristoteles  · 13-12-2016 - 09:27

Hi,

We try to prevent a page break inside a table/paragraph. Unfortunately nothing seems to work. (see shortened code below).

Using addTable isn't an option, we want to allow users to insert tables, images etc. Currently we only have libreoffice, editting table styles is not yet supported.

protected function generateTable(array $tableData) {
                $html = '<style>
                        p {page-break-inside:avoid;}
                        table{ width: 100%; padding:0px;margin:0px;text-align:left;page-break-inside:avoid;font-size:8pt;} 
                        tbody {page-break-inside:avoid;}
                        tr{ page-break-inside:avoid; } 
                        td{border: 1px solid #222;page-break-inside:avoid;}
                        th{border: 1px solid #222; text-align:left;page-break-inside:avoid; font-weight:normal;}
                </style><p><table><caption>test caption</caption>';
                foreach($tableData as $name => $value) {
                        $html.= '<tr>';
                        $html.= '<td style="width:40px;">'.trim($name).'</td>';
                        $html.= '<td style="width:80px;">'.trim(nl2br($value)).'</td>';
                        $html.= '</tr>';
                }
                $html.= '</table></p><br />';
                return $html;
        }

$createDocx = new CreateDocx();
$createDocx->embedHTML($this->generateKeyValueTable($tableData, array('strictWordStyles' => false)));

Kind Regards,

Aristoteles

Posted by admin  · 13-12-2016 - 11:25

Hello,

Using tr: {page-break-inside:avoid;} adds this tag to the DOCX:

<w:cantSplit/>

that disable the option "Allow row to break accross pages" in the DOCX.

Just as test to check it, could you try opening the DOCX using MS Word? We have teste it using MS Word 2007, MS Word 2013 and LibreOffice 5 and it's working perfectly.

For further support about this issue, please send an email to contact[at]phpdocx.com the DOCX output you get and other DOCX after fixing the content manually using MS Word or LibreOffice (this is changing the content to get the exact output you need to get).

Regards.

Posted by aristoteles  · 13-12-2016 - 13:03

Unfortunately this didn't solve it. I send the e-mail with the documents to you.

Kind Regards,

 

 

Aristoteles