I'm using TCPDF to print some tables of data: one big table (although usually not longer than a page) followed by a second, smaller one.
In some cases, the 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 that behavior: they would rather have the second table completely on a new page, ie insert the page break before the table, if both table cannot fit on a single page.
Of course if both tables fit on one page, no page break should be used.
So does anybody know if there is a way to instruct TCPDF not to insert a page break within a given table?
Start a transaction, insert the table, check if you are in a new page, if yes, roll back and add a page before insering your table.
VERY IMPORTANT: don't forget the TRUE calling 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 it helps michel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With