简体   繁体   中英

How can I push the image in the cell PHP FPDF?

Hi everyone in stackoverflow. I have struggle this problem all day today. As you can see on the image below the qr code are not in the column. This happen all pages on the last row. I will also attach my code. Please check if my code have problem. The counter are to display one row three column of same data. 在此处输入图像描述

<?php
include('../Connection/connection.php');
require('../FPDF/fpdf.php');


$QueryCustomer = "SELECT cus_name, cus_qr FROM tbl_customer WHERE cus_status = 1 AND cus_type = 1";
$ResultQueryCustomer = mysqli_query($con,$QueryCustomer);
$RowQueryCustomer = mysqli_num_rows($ResultQueryCustomer);

$QueryWebConfig = "SELECT * FROM tbl_web_config";
$ResultQueryWebConfig = mysqli_query($con,$QueryWebConfig);
$RowQueryWebConfig = mysqli_num_rows($ResultQueryWebConfig);
$ResQueryWebConfig = mysqli_fetch_array($ResultQueryWebConfig);



$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',8);    
$counter = 0;

while($ResQueryCustomer = mysqli_fetch_array($ResultQueryCustomer)){ 
    $pdf->Image("../CustomerQr/".$ResQueryCustomer['cus_qr'].".png", $pdf->GetX(), $pdf->GetY(), 40);
    $pdf->Cell( 65, 80,$ResQueryCustomer['cus_name'],1);

    $counter++;
    if($counter % 3 == 0) 
    {
      $pdf->Ln();

    }

}
$pdf->Output();
?>

Move your counter and test for a new page needed before you output the image and cell. You haven't posted what a full page looks like but it appears as though the image is just big enough to cause a page to spill but you aren't moving to a new page until it has already been output.

while($ResQueryCustomer = mysqli_fetch_array($ResultQueryCustomer)){ 
    $counter++;
    if($counter % 3 == 0) {
      $pdf->Ln();
    }
    $pdf->Image("../CustomerQr/".$ResQueryCustomer['cus_qr'].".png", $pdf->GetX(), $pdf->GetY(), 40);
    $pdf->Cell( 65, 80,$ResQueryCustomer['cus_name'],1);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM