Adding header/footer on every page

5,071 views
Skip to first unread message

Pavel Hanyš

unread,
Sep 2, 2015, 8:26:45 PM9/2/15
to dompdf
Hi, 

I need to add header and footer on every page in generated PDF file. Header has to be placed at the top, footer at the bottom of the page. So it should look like this

PAGE1
<header></header>
Some text .....
<footer></footer>

PAGE2
<header></header>
..... text continues here
<footer></footer>

Is there a way how to accomplish that?

Is it possible to recognize where page starts and where it ends?

Thank you for any reply

Pavel

John Bell

unread,
Sep 3, 2015, 10:03:38 AM9/3/15
to dom...@googlegroups.com
There is a good explanation of how to do this here:
http://stackoverflow.com/questions/7484318/header-in-pdf-page-using-dompdf-in-php

HTH

John
--
You received this message because you are subscribed to the Google Groups "dompdf" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dompdf+un...@googlegroups.com.
To post to this group, send email to dom...@googlegroups.com.
Visit this group at http://groups.google.com/group/dompdf.
For more options, visit https://groups.google.com/d/optout.

Noureddine bouaouina

unread,
Sep 6, 2015, 7:55:50 PM9/6/15
to dompdf
i've tried the example given in :
http://stackoverflow.com/questions/7484318/header-in-pdf-page-using-dompdf-in-php

but i got error :

Fatal error: Call to a member function page_text() on a non-object

$dompdf = new DOMPDF();

$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "bold");
$canvas->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
$dompdf->load_html($content);
$dompdf->render();

some one knows why did i got error?

NBO.

BrianS

unread,
Sep 8, 2015, 2:16:51 PM9/8/15
to dompdf
Currently the canvas isn't initialized until after you've rendered your document. Try it this way:

$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->render();
$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "bold");
$canvas->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));


Reply all
Reply to author
Forward
0 new messages