Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic Pagebreak in Dynamically generated TCPDF HTML page

I am dynamically pulling content into an HTML table that is used to build a PDF using TCPDF.

I need the page to auto-pagebreak when the content becomes too long for the page, but it seems to just keep appending to the first page even if it becomes longer than the actual page.

It is not simple row / column tabular data, so I cannot simply pagebreak after X rows, some fields can have very long "descriptions" that cause the row to go several lines (or even longer than a single page)

How can I force TCPDF to dynamically pagebreak when the content is longer than the page?

like image 361
Bryan Zwicker Avatar asked Jan 18 '26 02:01

Bryan Zwicker


2 Answers

Found the solution. I had a TCPDF option misconfigured.

Setting this made everything work as intended:

$pdf->SetAutoPageBreak(true, 0);
like image 197
Bryan Zwicker Avatar answered Jan 19 '26 17:01

Bryan Zwicker


One optimal solution would be:

//get the current page break margin:
$bMargin = $pdf->getBreakMargin();   

//get current auto-page-break mode:
$auto_page_break = $pdf->getAutoPageBreak();

//enable auto page break:
$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
like image 36
SumitK Avatar answered Jan 19 '26 16:01

SumitK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!