【发布时间】:2023-01-28 15:48:11
【问题描述】:
我正在尝试使用 fpdf 将页眉和页脚添加到我的 pdf 文件 我的控制器代码是:
<?php
namespace App\Controllers;
use App\Libraries\FPDF;
class Test extends BaseController
{
function Header()
{
$this->Image('logo.png',10,6,30);
$this->SetFont('Arial','B',15);
$this->Cell(80);
$this->Cell(30,10,'Test',1,0,'C');
$this->Ln(20);
}
function Footer()
{
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
public function index()
{
$this->pdf = new fpdf();
$this->pdf->AliasNbPages();
$this->pdf->AddPage();
$this->pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
$this->pdf->Cell(0,10,'Printing line number '.$i,0,1);
$this->response->setHeader("Content-Type", "application/pdf");
$this->pdf->Output();
}
}
pdf 输出只是没有页眉页脚的行号。有什么线索吗?
【问题讨论】:
-
将
Header()和Footer()放入控制器中没有任何效果。您必须扩展 FPDF 类。
标签: php codeigniter fpdf