Заголовок FPDF выглядит по-разному на страницах PDF? - PullRequest
0 голосов
/ 30 января 2020

Я использую FPDF для создания отчета в формате PDF на основе данных MySQL. Но у меня проблема со стилем моего заголовка.

Заголовок первой страницы выглядит так:

First Header

, но каждая страница после этого выглядит так:

Second Page Beyond Header

Вот мой полный код для отчета:

<?php

require("fpdf/fpdf.php");
//$db = new PDO('mysql:host=localhost; dbname=ccrp_db', 'root', '');
include("../dbconnect.php");

class Report extends FPDF {
    function header() {
        $this->Image('logo.png', 10, 6, 25, 25);
        $this->SetFont('Arial', 'B', 14);
        $this->Cell(200, 5, 'Cabarrus County GOP Convention' . ' ' . date("Y"), 0, 0, 'C');
        $this->Ln();
        $this->SetFont('Arial', '', 12);
        $this->Cell(200, 10, 'Attendance Report', 0, 0, 'C');
        $this->Ln(25);
    }

    function footer() {
        $this->SetY(-15);
        $this->SetFont('Arial', '', 8);
        $this->Cell(0, 10, 'Page '. $this->PageNo(), 0, 0,'R');
    }

    function headerSummary() {
        $this->SetFont('Arial', 'B', 12);
        $this->Cell(275, 5, 'Summary', 0, 0, 'L');
        $this->Ln(10);
        $this->SetFont('Arial', 'B', 10);
        $this->SetLeftMargin(50);
        $this->Cell(20, 10, 'Precinct', 1, 0, 'C');
        $this->Cell(40, 10, 'Delegates Present', 1, 0, 'C');
        $this->Cell(40, 10, 'Delegates Absent', 1, 0, 'C');
        $this->Cell(20, 10, 'Total', 1, 0, 'C');
        $this->Ln();

    }

    function viewSummary() {
        $this->SetFont('Arial', '', 8);
        global $pdo;
        $sql = "SELECT IFNULL(m.precinct, 'Totals') as 'precinct', COUNT(at.member_id) as 'delegates_present', COUNT(ab.member_id) as 'delegates_absent', COUNT(at.member_id) + COUNT(ab.member_id) as 'total' FROM members m LEFT JOIN attendance as at ON at.member_id = m.id LEFT JOIN absence as ab ON ab.member_id = m.id GROUP BY m.precinct WITH ROLLUP;";
        $stmt = $pdo->prepare($sql);
        $stmt->execute();
        while($data = $stmt->fetch(PDO::FETCH_OBJ)) {
            $this->Cell(20, 10, $data->precinct, 1, 0, 'C');
            $this->Cell(40, 10, $data->delegates_present, 1, 0, 'C');
            $this->Cell(40, 10, $data->delegates_absent, 1, 0, 'C');
            $this->Cell(20, 10, $data->total, 1, 0, 'C');
            $this->Ln();
        }
    }
}

$pdf = new Report();
$pdf->AliasNbPages();
$pdf->AddPage('P', 'Letter', 0);
$pdf->headerSummary();
$pdf->viewSummary();
$pdf->Output();

?>

Как я могу сделать заголовок выглядит одинаково на всех страницах? Я не уверен, что я сделал не так ...

...