TCPDF / FPDF - Page break issue

前端 未结 1 1854
谎友^
谎友^ 2021-02-09 09:56

I\'m trying to create a PDF file with a table of data.. But when a page break is met it jumps to a new page everytime a new multicell is added to the page at the break point lev

相关标签:
1条回答
  • 2021-02-09 10:33

    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.

    0 讨论(0)
提交回复
热议问题