TCPDF / FPDF - Page break issue

三世轮回 提交于 2019-12-03 07:29:43

The problem is that in the Cell() method (which is called in MultiCell()) FPDF allways adds a new page if the the current Y position + the height of the new cell is greater than the allowed page height.

The default page height seems to be 297, with SetAutoPageBreak() you substract 150 from it. So when Y + cell_height is graeter than 147 you allways get a new page when calling your cnstr_cell().

To prevent this you need to call AddPage() by yourself. Add this check in your add_product() method:

$x = $this->width;
$y = $this->pdf->GetY();

if (($y + $this->line_height) >= 147) {
    $this->pdf->AddPage();
    $y = 0; // should be your top margin
}

Btw. I also had to generate a dynamic PDF recently, I ended up using wkhtmltopdf, it was way more easy to use and customize than all the PHP libraries. I suggest to take a look at it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!