我是FPDF的新手,我正在尝试更改页眉和页脚, 我用的时候
function Header()
{
$this->SetFont('Arial','B',15);
$this->Cell(80);
$this->Cell(30,10,'Title',1,0,'C');
$this->Ln(20);
}
有错误说
'无法重新声明标题()',
所以我问的是,还有其他方法来调用页眉和页脚吗?喜欢
$pdf->header->SetFont('Arial','B',15)
还是什么?
这是我的代码,我从FPDF的教程2中复制了它,我不想要它的视图,我想在控制器中它所以它可以一直调用
public function tutorial2()
{
$this->load->library('myfpdf');
// function Header()
// {
// $this->SetFont('Arial','B',15);
// $this->Cell(80);
// $this->Cell(30,10,'Title',1,0,'C');
// $this->Ln(20);
// } -- the Header function that is normally used
$pdf = new FPDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
//$pdf->footer->SetY(-15);
//$pdf->footer->SetFont('Arial','I',8);
//$pdf->footer->Cell(0,10,'Page '.$pdf->footer->PageNo().'/{nb}',0,0,'C'); -- not actually a working, or is there another way?
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,'Printing line number '.$i,0,1);
$pdf->Output();
}
答案 0 :(得分:1)
从website下载FPDF。下载文件后解压缩,你会找到一个名为“fpdf181”的文件夹(其中181是FPDF的版本)。
代码:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require(APPPATH . 'third_party/fpdf181/fpdf.php');
class CustomFPDF extends FPDF {
public function header($family){
$this->SetFont($family,'B',15);
$this->Cell(80);
$this->Cell(30,10,'Title',1,0,'C');
$this->Ln(20);
}
public function getInstance(){
return new CustomFPDF();
}
}
?>
现在在“application / controllers”中创建一个控制器,并在您使用FPDF的函数中使用以下命令:
$this->load->library('CustomFPDF');
$pdf = $this->customfpdf->getInstance();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->header('Arial');
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,'Printing line number '.$i,0,1);
$pdf->Output();