如何使 table 页眉和 table 页脚出现在每个页面上?
How to make table header and table footer appear on each page?
table 页脚和页眉仅出现在页面的开头和结尾。我正在使用 FPDF。
这是代码:
$pdf = new myPDF();
$pdf->AliasNbPages('{nb}');
$pdf->AddPage('L', 'A4', 0);
$pdf->headerTable();
$pdf->viewTable($con);
$pdf->footerTable();
$pdf->Output();
这是我的 PDF class:
<?php
$con = new PDO('mysql:host=localhost;dbname=db_tc', 'root', '');
require('function.php');
require('fpdf/fpdf.php');
class myPDF extends FPDF
{
function header()
{
$this->SetleftMargin(30);
$this->SetFont('Times', 'B', 14);
$this->Cell(0, 10, 'Office 1', 0, 0, 'C');
$this->Ln(20);
}
function footer()
{
$this->SetY(-15);
$this->SetFont('Times', '', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
}
function headerTable()
{
$this->SetleftMargin(20);
$this->SetFillColor(255, 213, 31);
$this->SetDrawColor(50, 50, 100);
$this->SetFont('Times', 'B', 12);
$this->Cell(15, 10, 'Nomor', 1, 0, 'C', true);
$this->Cell(40, 10, 'Tanggal Cek', 1, 0, 'C', true);
$this->Cell(40, 10, 'Type Unit', 1, 0, 'C', true);
$this->Cell(40, 10, 'Serial Number', 1, 0, 'C', true);
$this->Cell(40, 10, 'Serial Number2', 1, 0, 'C', true);
$this->Cell(30, 10, 'Lokasi', 1, 0, 'C', true);
$this->Cell(30, 10, 'Ruangan', 1, 0, 'C', true);
$this->Ln();
}
function footerTable()
{
$this->SetleftMargin(30);
$this->SetFillColor(255, 213, 31);
$this->SetDrawColor(50, 50, 100);
$this->SetFont('Times', 'B', 12);
$this->Cell(15, 10, 'Nomor', 1, 0, 'C', true);
$this->Cell(40, 10, 'Tanggal Cek', 1, 0, 'C', true);
$this->Cell(40, 10, 'Type Unit', 1, 0, 'C', true);
$this->Cell(40, 10, 'Serial Number', 1, 0, 'C', true);
$this->Cell(40, 10, 'Serial Number2', 1, 0, 'C', true);
$this->Cell(30, 10, 'Lokasi', 1, 0, 'C', true);
$this->Cell(30, 10, 'Ruangan', 1, 0, 'C', true);
$this->Ln();
}
function viewTable($con)
{
$this->SetleftMargin(30);
$this->SetFont('Times', '', 12);
$this->SetFillColor(224, 224, 224);
$stmt = $con->query("SELECT * FROM officepakai");
while ($data = $stmt->fetch(PDO::FETCH_OBJ)) {
$this->Cell(15, 10, $data->Nomor, 1, 0, 'C', true);
$this->Cell(40, 10, $data->Tanggal_Cek, 1, 0, 'L', true);
$this->Cell(40, 10, $data->Type_Unit, 1, 0, 'L', true);
$this->Cell(40, 10, $data->Serial_Number, 1, 0, 'L', true);
$this->Cell(40, 10, $data->Serial_Number2, 1, 0, 'L', true);
$this->Cell(30, 10, $data->Lokasi, 1, 0, 'L', true);
$this->Cell(30, 10, $data->Ruangan, 1, 0, 'L', true);
$this->Ln();
}
}
}
$pdf = new myPDF();
$pdf->AliasNbPages('{nb}');
$pdf->AddPage('L', 'A4', 0);
$pdf->headerTable();
$pdf->viewTable($con);
$pdf->footerTable();
$pdf->Output();
?>
我还没有使用过这个 lib 但根据 it's documentation here 我会说只有 Header 和 Footer 方法被调用,但你似乎有一些名为 headerTable
和 footerTable
.
的自定义项
Header()
和 Footer()
方法是自动调用的,所以我相信调用其中的自定义方法应该可以解决问题:
function Header()
{
$this->SetleftMargin(30);
$this->SetFont('Times', 'B', 14);
$this->Cell(0, 10, 'Office 1', 0, 0, 'C');
$this->Ln(20);
$this->headerTable(); // add this
}
function Footer()
{
$this->SetY(-15);
$this->SetFont('Times', '', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
$this->footerTable(); // add this
}
table 页脚和页眉仅出现在页面的开头和结尾。我正在使用 FPDF。
这是代码:
$pdf = new myPDF();
$pdf->AliasNbPages('{nb}');
$pdf->AddPage('L', 'A4', 0);
$pdf->headerTable();
$pdf->viewTable($con);
$pdf->footerTable();
$pdf->Output();
这是我的 PDF class:
<?php
$con = new PDO('mysql:host=localhost;dbname=db_tc', 'root', '');
require('function.php');
require('fpdf/fpdf.php');
class myPDF extends FPDF
{
function header()
{
$this->SetleftMargin(30);
$this->SetFont('Times', 'B', 14);
$this->Cell(0, 10, 'Office 1', 0, 0, 'C');
$this->Ln(20);
}
function footer()
{
$this->SetY(-15);
$this->SetFont('Times', '', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
}
function headerTable()
{
$this->SetleftMargin(20);
$this->SetFillColor(255, 213, 31);
$this->SetDrawColor(50, 50, 100);
$this->SetFont('Times', 'B', 12);
$this->Cell(15, 10, 'Nomor', 1, 0, 'C', true);
$this->Cell(40, 10, 'Tanggal Cek', 1, 0, 'C', true);
$this->Cell(40, 10, 'Type Unit', 1, 0, 'C', true);
$this->Cell(40, 10, 'Serial Number', 1, 0, 'C', true);
$this->Cell(40, 10, 'Serial Number2', 1, 0, 'C', true);
$this->Cell(30, 10, 'Lokasi', 1, 0, 'C', true);
$this->Cell(30, 10, 'Ruangan', 1, 0, 'C', true);
$this->Ln();
}
function footerTable()
{
$this->SetleftMargin(30);
$this->SetFillColor(255, 213, 31);
$this->SetDrawColor(50, 50, 100);
$this->SetFont('Times', 'B', 12);
$this->Cell(15, 10, 'Nomor', 1, 0, 'C', true);
$this->Cell(40, 10, 'Tanggal Cek', 1, 0, 'C', true);
$this->Cell(40, 10, 'Type Unit', 1, 0, 'C', true);
$this->Cell(40, 10, 'Serial Number', 1, 0, 'C', true);
$this->Cell(40, 10, 'Serial Number2', 1, 0, 'C', true);
$this->Cell(30, 10, 'Lokasi', 1, 0, 'C', true);
$this->Cell(30, 10, 'Ruangan', 1, 0, 'C', true);
$this->Ln();
}
function viewTable($con)
{
$this->SetleftMargin(30);
$this->SetFont('Times', '', 12);
$this->SetFillColor(224, 224, 224);
$stmt = $con->query("SELECT * FROM officepakai");
while ($data = $stmt->fetch(PDO::FETCH_OBJ)) {
$this->Cell(15, 10, $data->Nomor, 1, 0, 'C', true);
$this->Cell(40, 10, $data->Tanggal_Cek, 1, 0, 'L', true);
$this->Cell(40, 10, $data->Type_Unit, 1, 0, 'L', true);
$this->Cell(40, 10, $data->Serial_Number, 1, 0, 'L', true);
$this->Cell(40, 10, $data->Serial_Number2, 1, 0, 'L', true);
$this->Cell(30, 10, $data->Lokasi, 1, 0, 'L', true);
$this->Cell(30, 10, $data->Ruangan, 1, 0, 'L', true);
$this->Ln();
}
}
}
$pdf = new myPDF();
$pdf->AliasNbPages('{nb}');
$pdf->AddPage('L', 'A4', 0);
$pdf->headerTable();
$pdf->viewTable($con);
$pdf->footerTable();
$pdf->Output();
?>
我还没有使用过这个 lib 但根据 it's documentation here 我会说只有 Header 和 Footer 方法被调用,但你似乎有一些名为 headerTable
和 footerTable
.
Header()
和 Footer()
方法是自动调用的,所以我相信调用其中的自定义方法应该可以解决问题:
function Header()
{
$this->SetleftMargin(30);
$this->SetFont('Times', 'B', 14);
$this->Cell(0, 10, 'Office 1', 0, 0, 'C');
$this->Ln(20);
$this->headerTable(); // add this
}
function Footer()
{
$this->SetY(-15);
$this->SetFont('Times', '', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
$this->footerTable(); // add this
}