[英]Image align error in FPDF
I am working with laravel to make a report using FPDF. 我正在与laravel合作,使用FPDF进行报告。 It runs properly but every bottom page's image is not aligned correctly. 它可以正常运行,但是每个底部页面的图像均未正确对齐。 I mentioned that with image. 我提到了图像。 How can I fix it? 我该如何解决? I am working with that long time. 我在那工作了很长时间。 Here is my code. 这是我的代码。 Thanks in advance. 提前致谢。
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;
}
You can check if the position of y is at bottom then add page and set y to initial of next page. 您可以检查y的位置是否在底部,然后添加页面并将y设置为下一页的开头。 You can do code like:- 您可以执行以下代码:
y = $pdf->GetY()
if (y > 275){
$pdf-> AddPage()
$pdf->SetY(20)
y = $pdf->GetY()
}
You can set position of Y according to your requirement. 您可以根据需要设置Y的位置。 Your code will be something like:- 您的代码将类似于:
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.