Forum


Replies: 3   Views: 3948
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