Php FPDF标题在PDF页面中看起来不同?

Php FPDF标题在PDF页面中看起来不同?,php,php-7,fpdf,Php,Php 7,Fpdf,我正在使用FPDF创建一个基于MySQL数据的PDF报告。但是我的标题有一个样式问题 第一个页面标题如下所示: 但之后的每一页都是这样的: 以下是我报告的完整代码: <?php require("fpdf/fpdf.php"); //$db = new PDO('mysql:host=localhost; dbname=ccrp_db', 'root', ''); include("../dbconnect.php"); class Report extends FPDF {

我正在使用FPDF创建一个基于MySQL数据的PDF报告。但是我的标题有一个样式问题

第一个页面标题如下所示:

但之后的每一页都是这样的:

以下是我报告的完整代码:

<?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();

?>

唯一真正引人注目的是
$this->SetLeftMargin(50)嗯。。。我注释掉了这一行,它起作用了,但现在表格与页面左侧对齐。如何将其与中心对齐?因为整个文档的边距都是统一的,所以我建议使用
$this->SetX(50)
而不是边距。这样,您可以根据需要重置X位置<代码>$x=$this->GetX()$这->SetX(50);/$这个->Ln()$这->SetX($x)这似乎起到了作用!尽管我对表中的SQL语句有问题。显然,缺席列没有获取任何数据,它应该在10-00行中有一个1?关于SQL疑难解答,您应该问一个单独的问题,因为它实际上是一个独立的问题,而不是与PDF对齐时遇到的问题。