首页 > 解决方案 > 如何在单元格 PHP FPDF 中推送图像?

问题描述

大家好,stackoverflow 中的每个人。我今天整天都在努力解决这个问题。正如您在下面的图像中看到的,二维码不在列中。这发生在最后一行的所有页面上。我还将附上我的代码。请检查我的代码是否有问题。计数器将显示一行三列相同的数据。 在此处输入图像描述

<?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();
?>

标签: phpfpdf

解决方案


在输出图像和单元格之前,移动计数器并测试所需的新页面。您尚未发布完整页面的外观,但看起来好像图像大到足以导致页面溢出,但您在输出之前不会移动到新页面。

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);

}

推荐阅读