[英]Image align error in FPDF
我正在與laravel合作,使用FPDF進行報告。 它可以正常運行,但是每個底部頁面的圖像均未正確對齊。 我提到了圖像。 我該如何解決? 我在那工作了很長時間。 這是我的代碼。 提前致謝。
public function img_pdf_full()
{
$data= visitor::where('flag', '1')
->orderBy('id', 'desc')
->get();
$pdf = new PDF_Code128(); //'P','mm',array(58,20)
$pdf->AddPage('L');
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,"Visitor's Log",0,0,'C');
$pdf->Ln();
$pdf->SetFont('Arial','B',10);
$pdf->Cell(12,10,'Photo',1,0,'C',0);
$pdf->Cell(40,10,'Name',1,0,'C',0);
$pdf->Cell(20,10,'Visitor ID',1,0,'C',0);
$pdf->Cell(20,10,'Date',1,0,'C',0);
$pdf->ln();
$pdf->SetFont('Arial','',7);
foreach ($data as $v) {
$image1 = public_path('storage/'.$v->v_photo);
$new_date = date("d F, Y", strtotime($v->v_date));
$pdf->Cell(12,10, $pdf->Image($image1, $pdf->GetX(), $pdf->GetY(), 11.5,10) ,1,0,'C',0);
$pdf->Cell(40,10,$v->v_name,1,0,'C',0);
$pdf->Cell(20,10,$v->v_id,1,0,'C',0);
$pdf->Cell(20,10,$new_date,1,0,'C',0);
$pdf->ln();
}
$pdf->ln();
$pdf->Output();
exit;
}
您可以檢查y的位置是否在底部,然后添加頁面並將y設置為下一頁的開頭。 您可以執行以下代碼:
y = $pdf->GetY()
if (y > 275){
$pdf-> AddPage()
$pdf->SetY(20)
y = $pdf->GetY()
}
您可以根據需要設置Y的位置。 您的代碼將類似於:
foreach ($data as $v) {
$image1 = public_path('storage/'.$v->v_photo);
$new_date = date("d F, Y", strtotime($v->v_date));
// code added by me
y = $pdf->GetY()
if (y > 275){
$pdf-> AddPage()
$pdf->SetY(20)
y = $pdf->GetY()
}
$pdf->Cell(12,10, $pdf->Image($image1, $pdf->GetX(),y, 11.5,10) ,1,0,'C',0);
$pdf->Cell(40,10,$v->v_name,1,0,'C',0);
$pdf->Cell(20,10,$v->v_id,1,0,'C',0);
$pdf->Cell(20,10,$new_date,1,0,'C',0);
$pdf->ln();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.