设置新行时,可以使用
我正在尝试使用PhP FPdf生成包含一些图像的pdf。我需要每页4(四)个图像,每行2(两)个图像。文档看起来很简单,但我仍然不明白为什么它不起作用。第一次在这个图书馆工作,很抱歉我犯了一些新手的错误。如果有人能给我一个更好的方法,我将不胜感激。这是我的密码。
$imagesPerPage = 1;
$imagesPerRow = 0;
if ($itens !== false) {
//Add a page if there's at least a single image
$pdf->AddPage();
foreach ($itens as $item) {
//if more than 4 images will generate another page
if($imagesPerPage > 4){
$pdf->AddPage();
$imagesPerPage = 1;
}
//Set image in their cordinates into the pdf file
$pdf->Image($item, $pdf->GetX(), $pdf->GetY(), 0);
$imagesPerRow ++;
//Put side by side or if the row is complete put bellow
if($imagesPerRow === 1){
$pdf->Cell(80, 0, "", 0, 0);
}else{
$pdf->Cell(80, 0, "", 0, 2);
$imagesPerRow = 0;
}
$imagesPerPage ++;
}
}
这是我得到的输出
在此处输入图像描述
$pdf->SetXY();
重置下一行的位置。
$imagesPerPage = 1;
$imagesPerRow = 0;
if ($itens !== false) {
//Add a page if there's at least a single image
$pdf->AddPage();
foreach ($itens as $item) {
//if more than 4 images will generate another page
if($imagesPerPage > 4){
$pdf->AddPage();
$imagesPerPage = 1;
}
//Set image in their cordinates into the pdf file
$pdf->Image($item, $pdf->GetX(), $pdf->GetY(), 0);
$imagesPerRow ++;
//Put side by side or if the row is complete put bellow
if($imagesPerRow === 1){
$pdf->Cell(80, 0, "", 0, 0);
}else{
$pdf->SetXY(15, 0);
$pdf->Cell(80, 0, "", 0, 2);
$imagesPerRow = 0;
}
$imagesPerPage ++;
}
}