簡體   English   中英

FPDF / PHP:頁腳頁顯示在下一頁的底部(空白頁)

[英]FPDF / PHP: Footer page is display at the bottom of the next page (Blank page)

目前,我創建了一個可以生成 PDF 的系統。 PDF 中的數據來自 MySQL 數據庫。 現在,我像這樣顯示數據

第一頁:只顯示一個數據。

單詞第二頁:將顯示數據(每頁最多 3 個數據)

更清楚地說,例如我有 6 個數據,它將顯示如下:

第一頁 = 1 個數據顯示

第二頁 = 3 數據顯示

第三頁2數據顯示

現在,我想添加頁腳。 頁腳將顯示在頁面的末尾(底部)。 我已經創建了頁腳。

如果最后一頁包含 1 或 2 個數據,則頁腳將顯示在該頁面的底部。 但是...如果最后一頁包含 3 個數據,頁腳將顯示在下一頁(空白頁)的底部。 我不知道是什么問題。 任何人都可以幫忙嗎?

下面是我的代碼

  $user3 = $conn->query("SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid LEFT JOIN ot_team ON ot_team.team_id = ot_users.team_id 
  WHERE ot_team.team_id = '".$_GET['team']."' AND report_date BETWEEN '".$_GET["from"]."' AND '".$_GET["to"]."' ORDER BY ot_report.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');
          }

          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');
          }

          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++;

      }

      $pdf->Footer($pdf->SetY(-48));

      $pdf->Footer($pdf->SetFont('Arial','B',9));
      $pdf->Footer($pdf->Cell(58,9,'Prepared by,',0,0,"C"));
      $pdf->Footer($pdf->Cell(58,9,'Verified by,',0,0,"C"));
      $pdf->Footer($pdf->Cell(58,9,'Approved by,',0,1,"C"));

  $pdf->Output();

  ?>

擴展 FPDF 類並修改默認頁腳。 任何時候啟動新頁面時,都會調用頁腳方法的內容,這應該會得到您想要的結果。

class PDF extends FPDF {
    function Footer() {
      $this->SetY(-48));
      $this->SetFont('Arial','B',9));
      $this->Cell(58,9,'Prepared by,',0,0,"C"));
      $this->Cell(58,9,'Verified by,',0,0,"C"));
      $this->Cell(58,9,'Approved by,',0,1,"C"));
    }  // end of the Footer function
}  // end of the PDF class

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM