【问题标题】:Add a Footer in FPDI在 FPDI 中添加页脚
【发布时间】:2015-10-08 08:07:27
【问题描述】:

感谢 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 的手册中没有找到关于如何保留 Footer 的解释...我确信解决问题很容易,只是我没有找到方法!

谢谢!

【问题讨论】:

  • 你试过在$pdf-&gt;AddPage()之后手动调用$pdf-&gt;Footer()吗?

标签: php pdf fpdf fpdi


【解决方案1】:

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

改变一下

$pdf = new FPDI();

$pdf = new PDF();

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

【讨论】:

  • 使用 autload 我有一个错误:“致命错误:找不到类 'setasign\Fpdi'”你有解决方案吗?请
  • @Rocstar 不查看代码就无法确定“setasign”的来源,但您可能需要为 FPDI 指定完整的命名空间或使用“Use”语句。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-29
  • 2017-07-27
  • 2012-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多