I would like to generate PDFs from HTML (twig), including the page numbers, and followed this example:
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
}
It basically works, but I'm trying to add page numbers, which is not working:
// ...
$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
Problem: the page numbers are added to the last page. I tried $y = -10
, but this doesn't add anything to the previous page; it just hides the page number.
Does anyone know, how I could add page numbers using writeHTMLCell()
?
Thanks in advance!