簡體   English   中英

FPDF Header 頁腳 Codeigniter 4 未顯示

[英]FPDF Header Footer Codeigniter 4 Not Showing

我正在嘗試使用 fpdf 將 header 和頁腳添加到我的 pdf 文件中 我的 controller 代碼是:

<?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 output 只是行號,沒有 header 頁腳。 有什么線索嗎?

現在它正在通過在 FPDF tuto2 之后稍微更改代碼來工作。

<?php
namespace App\Controllers;

use App\Libraries\FPDF;

class PDF extends FPDF
{
    function Header()
    {
        $this->Image('logo.png',10,6,30);
        $this->SetFont('Arial','B',15);
        $this->Cell(80);
        $this->Cell(30,10,'Title',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');
    }
}

$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
    $pdf->Cell(0,10,'Printing line number '.$i,0,1);
$pdf->Output();

感謝 Olivier PLATHEY 提供的出色而簡單的 FPDF class

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM