gpt4 book ai didi

php - 在 FPDI 中添加页脚

转载 作者:搜寻专家 更新时间:2023-10-31 20:37:29 32 4
gpt4 key购买 nike

感谢 FPDF,我创建了一个 PDF 生成器,它使用来自 mysql 数据库的数据并且运行良好。页数可变。

然后我想向每个 PDF 添加一些从其他 PDF 文件导入的页面。添加页数和导入文件地址也是可变的。

它工作得很好,除了我的页脚不再出现。我想在每个页面上保留这个页脚,生成器创建的页面和导入的页面。谁能告诉我问题出在哪里?..

这是我的代码:

require_once('gpdf/fpdf.php');
require_once('gpdf/fpdi.php');

class PDF extends FPDI
{

function Header()
{


}

function Footer()
{
// Positionnement à 1,5 cm du bas
$this->SetY(-15);
// Police Arial italique 8
$this->SetFont('Arial','I',8);
// Numéro de page
$this->Cell(0,10,'Devis from MyCompany - Page '.$this->PageNo().'/{nb}'.' Paraphes :',0,0,'C');
}

}

// Instanciation de la classe dérivée



$pdf = new FPDI();
$pdf->AliasNbPages();

$pdf->AddPage();
// Here is page 1, you don't need the details
$pdf->AddPage();
// Here is page 2, some other pages can come too


// Then begins the importation

// get the page count
$pageCount = $pdf->setSourceFile('cgua/cgu_'.$customer['num'].'.pdf');
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);

// create a page (landscape or portrait depending on the imported page size)
if ($size['w'] > $size['h']) {
$pdf->AddPage('L', array($size['w'], $size['h']));
} else {
$pdf->AddPage('P', array($size['w'], $size['h']));
}

// use the imported page
$pdf->useTemplate($templateId);
}


$pdf->Output('devis.pdf','I');

我在 FPDI 的手册中没有找到关于如何保留我的页脚的解释......我确信很容易解决这个问题,我只是没有找到方法!

谢谢!

最佳答案

您创建了一个继承 FPDI 类的新类。这个新类 PDF 正确定义了 Footer 方法。但是随后您实例化了 FPDI 类,而不是 PDF 类。

只是改变

$pdf = new FPDI();

$pdf = new PDF();

这样您就可以实例化您的新类并查看新的 Footer 方法的结果。

关于php - 在 FPDI 中添加页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31495537/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com