Tcpdf: prevent page breaks inside a block

I use TCPDF to print some data tables: one large table (although usually no longer than a page), and the second a smaller one. In some cases, two tables together are longer than one page, so TCPDF inserts a page break in the middle of the second table. My clients want to avoid this behavior: they would rather have a second table entirely on a new page, that is, insert a page break before the table if both tables cannot fit on the same page.

Of course, if both tables fit on the same page, you should not use page breaks.

Does anyone know if there is a way to tell TCPDF not to insert a page break into a given table?

+4
source share
3 answers

Run the transaction, insert the table, check if you are on a new page, if so, roll back and add the page before inserting the table.

VERY IMPORTANT : do not forget that TRUE call rollback:

$this->startTransaction(); $start_page = $this->getPage(); $this->writeHTMLCell( 0, 0, '', '', $html, 0, 1, false, true, 'C' ); $end_page = $this->getPage(); if ($end_page != $start_page) { $this->rollbackTransaction(true); // don't forget the true $this->AddPage(); $this->writeHTMLCell( 0, 0, '', '', $html, 0, 1, false, true, 'C' ); }else{ $this->commitTransaction(); } 

Hope this helps Michelle

+9
source

according to the documents, it is possible to add nobr = "true" to the table tag as an attribute.

  $tbl = <<<EOD <table border="1" cellpadding="2" cellspacing="2" nobr="true"> <tr> <th colspan="3" align="center">NON-BREAKING TABLE</th> </tr> <tr> <td>1-1</td> <td>1-2</td> <td>1-3</td> </tr> </table> EOD; $pdf->writeHTML($tbl, true, false, false, false, ''); 

http://www.tcpdf.org/examples/example_048.phps

+4
source

Calculate the height of the second table in advance. Use the checkPageBreak method to add a page break if necessary.

-1
source

Source: https://habr.com/ru/post/1391414/


All Articles