Skip to content
Advertisement

FPDF: Add Comment at the last page

Currently, I created a system that can generate data from MySQL to pdf. The arrangement of data that display to the pdf is:

1) The first page will display only 1 data rows

2) 2nd Page onwards will display a maximum of 3 data row per page.

The display was successful. Now, created a comment box at the end of the page. The problem is, the comment box is displayed at the end of data row. I want

$pdf->SetFont('Arial','',10);
$user = $conn->query("
SELECT * 
  FROM ot_users u
  JOIN ot_team t
    on u.team_id = t.team_id 
 WHERE u.team_id = '".$_GET['team']."' 
   AND u.roles_id IN(4,5) 
 ORDER 
    BY u.roles_id ASC
");
  while ($row = $user->fetch(PDO::FETCH_ASSOC)){
      $pdf->Cell(20,8,$row['badgeid'],1,0);
      $pdf->Cell(154,8,$row['fullname'],1,1); 
  }
  $pdf->Cell(0,10,'',0,1,"C");

$user3 = $conn->query("
SELECT * 
  FROM ot_report r
  LEFT 
  JOIN ot_users u 
    ON r.badgeid = u.badgeid 
  LEFT 
  JOIN ot_team t
    ON t.team_id = u.team_id 
WHERE t.team_id = '".$_GET['team']."' 
   AND report_date BETWEEN '".$_GET["from"]."' AND '".$_GET["to"]."' 
 ORDER 
    BY r.report_date DESC
");
    $count = 0;
    while ($row = $user3->fetch(PDO::FETCH_ASSOC)){

        $pdf->SetFont('Arial','B',10);
        $pdf->Cell(20,7,'Date:',1,0);
        $pdf->Cell(67,7,date('d-m-Y',strtotime($row['report_date'])),1,0);
        $pdf->Cell(20,7,'Time:',1,0);
        $pdf->Cell(34,7,"From: ".date('H:i',strtotime($row['ot_start'])),1,0);
        $pdf->Cell(33,7,"To: ".date('H:i',strtotime($row['ot_end'])),1,1); 
        $pdf->Cell(87,7,'Before',1,0,'C');
        $pdf->Cell(87,7,'After',1,1, 'C');

        $logo = file_get_contents('../../images/faces/noimage.png');

        if(!isset($row['photo_before']) || empty($row['photo_before'])) {
          $pdf->Cell(87, 57, $pdf->MemImage($logo, $pdf->GetX()+20, $pdf->GetY()+5, 47,47,), 1, 0, 'C');
        }else{ 
          //$pdf->Cell(87, 57, $pdf->MemImage(base64_decode($row['photo_before']), $pdf->GetX()+21, $pdf->GetY()+2, 45,53,), 1, 0, 'C');
          $pdf->Cell(87, 57, $pdf->Image($row['photo_before'], $pdf->GetX()+21, $pdf->GetY()+2, 45,53,), 1, 0, 'C');
        }

        if(!isset($row['photo_after']) || empty($row['photo_after'])) {
          $pdf->Cell(87, 57, $pdf->MemImage($logo, $pdf->GetX()+20, $pdf->GetY()+5, 47,47,), 1, 1, 'C');
        }else{ 
          //$pdf->Cell(87, 57, $pdf->MemImage(base64_decode($row['photo_after']), $pdf->GetX()+21, $pdf->GetY()+2, 45,53,), 1, 1, 'C');
          $pdf->Cell(87, 57, $pdf->Image($row['photo_before'], $pdf->GetX()+21, $pdf->GetY()+2, 45,53,), 1, 0, 'C');
        }

        if ($row['time_photo_before'] == null){
          $pdf->Cell(87,7,'-',1,0, 'C');
        }else{
          $pdf->Cell(87,7,$row['time_photo_before'],1,0, 'C');
        }

        if ($row['time_photo_after'] == null){
          $pdf->Cell(87,7,'-',1,1, 'C');
        }else{
          $pdf->Cell(87,7,$row['time_photo_after'],1,1, 'C');
        }

        if ((($count - 3) % 3) === 0) {


          $pdf->AddPage();
          $pdf->Cell(60,7,'',0,1,"C");

        }

      $count++;

    }
    // Editing starts
    $leftPageMargin = 10;
    $heightAfterRows = 10;
    $pdf->SetXY($leftPageMargin, $pdf->GetY() + $heightAfterRows);
    // Editing ends
    $pdf->Cell(0,60,"Comment",1,1, 'L');

Can anyone help me?

Advertisement

Answer

I hope this helps and that I understand your question right:

You can try this before your comment.

$leftPageMargin = 10;
$heightAfterRows = 10;
$pdf->SetXY($leftPageMargin, $pdf->GetY() + $heightAfterRows);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement