I use dompdf
class and I need page numembering for every page
I did this and it works:
$dompdf = new Dompdf();
$dompdf->load_html($html);
$dompdf->render();
$canvas = $dompdf->get_canvas();
$font = $dompdf->getFontMetrics()->get_font("helvetica", "bold");
$canvas->page_text(72, 18, "Header: {PAGE_NUM}", $font, 6, array(0,0,0));
What I need is just skip first page and start numbering from second page.
How can I do this?
Here is what worked for me:
$dompdf = new Dompdf();
$dompdf->load_html($html);
$dompdf->render();
$canvas = $dompdf->get_canvas();
$cpdf = $canvas->get_cpdf();
$font = $dompdf->getFontMetrics()->get_font("helvetica", "bold");
$firstPageId = $cpdf->getFirstPageId();
$objects = $cpdf->objects;
$pages = array_filter($objects, function($v) {
return $v['t'] == 'page';
});
$number = 1;
foreach($pages as $pageId => $page) {
if(($pageId + 1) !== $firstPageId) {
$canvas->reopen_object($pageId + 1);
$canvas->text(72, 18, "Header: $number", $font, 6, array(0,0,0));
$canvas->close_object();
$number++;
}
}
$dompdf->stream();
How this works:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With