FPDF - Data not flowing across multiple pages as expected

26 Views Asked by At

I'm using the FPDF PHP Library to generate a PDF and I'm using a foreach loop to loop through some data and generate various groups of cell with information and an image inside.

I'd like for my generated PDF to firstly loop through but with each loop I need the cells to appear underneath each other rather than be grouped together as they are now (screenshot below).

enter image description here

The second thing I need to ensure is that with each loop they flow down and when there's not enough room on the page for the next loop, it begins a new page.

My current code loop is below:

if ($linked_documents) {
    $pdf -> SetY(120);
    foreach ($linked_documents as $document) {
        $pdf -> SetTextColor(51,51,51);
        $pdf -> SetFont('Manrope SemiBold', '', 10);
        $pdf -> Cell(20,7,'ID',1,0,'L',0);
        $pdf -> Cell(0,7,'Comments',1,0,'L',0);
        $pdf -> Ln(7);
        $pdf -> SetFont('Manrope Light', '', 10);
        $pdf -> Cell(20,7,'1',1,0,'L',0);
        $pdf -> Cell(0,7,'Comments about this image',1,0,'L',0);
        $pdf -> Ln(7);
        $image_1 = "image.png";
        $image_1_top_margin = $pdf->GetY() + 5;
        $pdf -> Cell(0,45,$pdf->Image($image_1, 15, $image_1_top_margin, 0, 35),1,0,'L',0);
    }
}

How can I achieve these two thing? Any help would be much appreciated. Thanks!

0

There are 0 best solutions below