I'm using dompdf 0.7.0 and try to write down text in PHP on my pdf after rendering. I need text on specific pages and found the following from Answer from Brian DomPDF {PAGE_NUM} not on first page
The function page_script sound like the correct answer. I could check if loop is currently on page 3 or whatever.
Does I have to enable any options for this function?
Example:
$dompdf = new Dompdf( $options );
$dompdf->set_option('default_font', 'open sans');
$dompdf->set_option('fontHeightRatio', 1);
$dompdf->setPaper('A4')
$dompdf->set_option('enable_html5_parser', true);
$dompdf->set_option('enable_php', true);
$dompdf->loadHtml( $html );
$dompdf->render();
$canvas = $dompdf->get_canvas();
$canvas->page_script('
if ($PAGE_NUM > 1) {
$current_page = $PAGE_NUM-1;
$total_pages = $PAGE_COUNT-1;
$canvas->text(0, 0, "$current_page / $total_pages", "open sans condensed", 10, array(0,0,0));
}
');
It still be shown on my first page.