Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jrmypttrsn's avatar

Laravel-dompdf: footer on every page except the last?

I'm relatively new to programming and especially to Laravel and dompdf, so bear with me.

I have a pdf with a table that can flow into subsequent pages if necessary. Below the table is a line of text (ex. "The data in this table is can be verified at www.foo.bar"). I am using a script,

if ( isset($pdf) ) {
                $font = Font_Metrics::get_font("times_new_roman", "bold");
                $pdf->page_text(279, 764, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, 12, array(0,0,0));
            }

to include a page number of page count on the footer of each page. I need to also include the line of text ("The data in this table is can be verified at www.foo.bar") in the footer if the document is longer than one page, otherwise the line can remain where it is displayed below the table.

Is this possible or am I asking too much of dompdf?

0 likes
3 replies
SamStenton's avatar

I'm not familiar with dompdf but if you've got access to PAGE_NUM and PAGE_COUNT it should be fairly easy.

if($page_num == $page_count) {
    // Last page
    // Output
}

you can also check if the document is only one page long:

if($page_count == 1) {
    //Only Page
}
jimmy0699's avatar

i had simillar issue, and i had to do this in pdf template using css

Please or to participate in this conversation.