在现有的pdf文件fpdi中添加页脚

问题描述 投票:0回答:1

对于使用fpdi的现有pdf文件的页码,我必须遵循以下代码:

<?php
use setasign\Fpdi\Fpdi;

require_once('Library/fpdf182/fpdf.php');
require_once('Library/FPDI2/src/autoload.php');

class PDF extends FPDF
{
    function Footer()
    {
        // Go to 1.5 cm from bottom
        $this->SetY(-15);
        // Select Arial italic 8
        $this->SetFont('Arial','I',8);
        // Print centered page number
        $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
    }
}


// initiate PDF
$pdf = new PDF();

// set the source file
$pageCount = $pdf->setSourceFile("test.pdf");

for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
    $tplIdx = $pdf->importPage($pageNo);


    // import page 1
    $pdf->AddPage();
    $pdf->useTemplate($tplIdx);


}

$pdf->Output();


?>

代码的结果是:

Uncaught Error: Call to undefined method PDF::setSourceFile()
php pdf fpdf fpdi
1个回答
2
投票

setSourceFile方法是FPDI扩展的一部分,本身不属于Fpdf。 FPDI不包含在此软件包中-回答您的问题“是的,它不包含在内”。

[请先安装FPDI软件包,您可以在Github上找到它here

© www.soinside.com 2019 - 2024. All rights reserved.