为什么我的FPDF类函数SetMargins()不影响第一行?

BAG*_*man 2 php mysql fpdf

我正在使用FPDF类根据mysql查询的结果创建一个pdf.信息按照预期在表格中输出为pdf,但是当我使用SetMargins()设置页边距时出现问题.除第一行外的所有内容都有效.第一行似乎是硬编码到某个位置或边距定义.

这是我的代码:

class Table extends FPDF
{
    public function CreateTable($header, $data)
    {
        //Header
        $this->SetFillColor(255);
        $this->SetTextColor(0);
        $this->SetFont('Arial','B', 12);
        foreach ($header as $col) {
            $this->Cell($col[1], 10, $col[0], 1, 0, 'C');
            //Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])
        }

        $this->Ln();

        //Data
        $this->SetFillColor(255);
        $this->SetTextColor(0);
        $this->SetFont('Arial', '', 8);
        foreach ($data as $row) {

            $i = 0;
            foreach ($row as $field) {
                $this->Cell($header[$i][1], 6, $field, 1, 0, 'C');
                $i++;

            }
            $this->Ln();
        }

    }
}


//column headings for the department table
$dept_header = array(array('Name', 75), array('Phone', 40), array('Fax', 40));

//column headings for the team tables
$team_header = array(array('Name', 35), array('Role', 30), array('Office', 25), array('Cell', 25), array('Email', 45), array('Pager', 25));

//get data
$query = new ConnectQuery();
$dept_data = $query->all('SELECT * FROM Table');

$team_data = $query->all('SELECT CONCAT_WS(" ", FIRST_NAME, LAST_NAME), JOB_ROLE, OFFICE_PHONE, MOBILE_PHONE, EMAIL, PAGER_NUM FROM Table2');


$pdf = new Table('P', 'mm', 'Letter');

$pdf->AddPage();
$pdf->SetMargins(5, 5);
$pdf->CreateTable($team_header, $team_data);
$pdf->CreateTable($dept_header, $dept_data);


$pdf->Output();

?>
Run Code Online (Sandbox Code Playgroud)

Jan*_*bon 11

只需在添加第一页之前定义页边距即可.该位置不会被setMargins()调用重置,这会导致在AddPage()中设置的"硬编码的postition":

$pdf = new Table('P', 'mm', 'Letter');
$pdf->SetMargins(5, 5);
$pdf->AddPage();
Run Code Online (Sandbox Code Playgroud)