Header Footer

986 views
Skip to first unread message

moint

unread,
Oct 7, 2009, 9:21:58 AM10/7/09
to dompdf
How can a add header and footer when the code is as follows:

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("List.pdf");

Thanks.

BrianS

unread,
Oct 22, 2009, 2:00:22 PM10/22/09
to dompdf
Typically you would add some inline script to your HTML document prior
to rendering it with DOMPDF. See the FAQ (http://code.google.com/p/
dompdf/wiki/FAQ). Note that this script should appear within the body
tag of the document, and probably as the first element within the body
if you want to make sure it affects every page.

If, for some reason, it isn't possible to add this code to your HTML
document, you could use some basic string replacement to insert it
before rendering with DOMPDF. Something like:

$script = '<script type="text/php">
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("verdana", "bold");
$pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font,
6, array(0,0,0));
}
</script>';
$html = str_replace('<body>', '<body>'.$script, $html);
Reply all
Reply to author
Forward
0 new messages