Symfony3 / TCPDF:来自HTML的PDF,页码为

时间:2016-09-04 20:51:27

标签: php pdf-generation symfony tcpdf

我想从HTML生成 PDF (twig),包括页码,并遵循this示例:

public function returnPDFResponseFromHTML($html){
    //set_time_limit(30); uncomment this line according to your needs
    // If you are not in a controller, retrieve of some way the service container and then retrieve it
    //$pdf = $this->container->get("white_october.tcpdf")->create('vertical', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    //if you are in a controlller use :
    $pdf = $this->get("white_october.tcpdf")->create('vertical', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetAuthor('Our Code World');
    $pdf->SetTitle(('Our Code World Title'));
    $pdf->SetSubject('Our Code World Subject');
    $pdf->setFontSubsetting(true);
    $pdf->SetFont('helvetica', '', 11, '', true);
    //$pdf->SetMargins(20,20,40, true);
    $pdf->AddPage();

    $filename = 'ourcodeworld_pdf_demo';

    $pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
    $pdf->Output($filename.".pdf",'I'); // This will output the PDF as a response directly
}

它基本上有效,但我正在尝试添加页码,但这不起作用:

    // ...
    $pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);

    $y = 10; // later replaced by the real position
    for ($i = 0, $c = $pdf->getNumPages(); $i < $c; $i++) {
        $pdf->writeHTMLCell(0, 0, 0, $y, "PAGE $i");
        $y += 10;
    }

    $pdf->Output($filename.".pdf",'I'); // This will output the PDF as a response directly

问题:页码被添加到最后一页。我试过$y = -10,但这并没有在上一页添加任何内容;它只是隐藏了页码。

有谁知道,我如何使用writeHTMLCell()添加页码?

提前致谢!

0 个答案:

没有答案