Reputation: 360
I am using DOMPDF to generate PDF file. I want footer(Page number and Page count) in all pages except last page. currently i am having this code
$dompdf = new DOMPDF();
$html = ob_get_contents();
$dompdf->load_html($html);
$dompdf->render();
$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "12");
$canvas->page_text(500, 770, "Page {PAGE_NUM} - {PAGE_COUNT}", $font, 10, array(0,0,0));
$canvas->page_text(260, 770, "Canny Pack", $font, 10, array(0,0,0));
$canvas->page_text(43, 770, $date, $font, 10, array(0,0,0));
$pdf = $dompdf->output();
the above code in showing footer in all pages. but i dont want footer in last page.
can anyone tell me how to do this?
Upvotes: 1
Views: 8925
Reputation: 13944
The page_text()
methods runs on all pages without restriction. If you use the text()
method in combination with the page_script()
method you can programmatically determine the pages on which you want to insert the text.
Something like the following should work:
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$canvas = $dompdf->get_canvas();
$canvas->page_script('
if ($pdf->get_page_number() != $pdf->get_page_count()) {
$font = Font_Metrics::get_font("helvetica", "12");
$pdf->text(500, 770, "Page {PAGE_NUM} - {PAGE_COUNT}", $font, 10, array(0,0,0));
$pdf->text(260, 770, "Canny Pack", $font, 10, array(0,0,0));
$pdf->text(43, 770, $date, $font, 10, array(0,0,0));
}
');
$pdf = $dompdf->output();
Upvotes: 3