生成具有顺序图像 FPDF 的 PDF
Generating a PDF with sequential order images FPDF
我正在尝试使用 PhP FPDF 生成包含一些图像的 pdf。我每页需要 4(四)张图像,每行需要 2(两)张图像。 documentation 似乎很简单,但我仍然不明白为什么它不起作用。第一次使用这个库,如果我犯了一些新错误,我深表歉意。如果有人可以建议我更好的方法,我将不胜感激。这是我的代码。
$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 ++;
}
}
我正在尝试使用 PhP FPDF 生成包含一些图像的 pdf。我每页需要 4(四)张图像,每行需要 2(两)张图像。 documentation 似乎很简单,但我仍然不明白为什么它不起作用。第一次使用这个库,如果我犯了一些新错误,我深表歉意。如果有人可以建议我更好的方法,我将不胜感激。这是我的代码。
$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 ++;
}
}