image on header/footer only shown in the last page

3,935 views
Skip to first unread message

yoga

unread,
Mar 7, 2011, 6:17:28 AM3/7/11
to dompdf
hi all,

I just try the latest dompdf 0.6.2 and having a problem. Image
attached to my header and footer only shown on the last page of
generated pdf. Here's my header and footer script :

<script type="text/php">
if(isset($pdf)){
$w = $pdf->get_width();
$h = $pdf->get_height();

$footer = $pdf->open_object();

$img_w = 1.17 * 72;
$img_h = 0.88 * 72;
$pdf->image("icon.png", "png", 72, 0, $img_w, $img_h);

$img_w = 1.97 * 72;
$img_h = 0.47 * 72;
$pdf->image("logo.png", "png", 72, $h - 42, $img_w, $img_h);

$pdf->close_object();

$pdf->add_object($footer, "all");
}
</script>

Is there anyone could tell me how to make image attached in header and
footer on all page?

BrianS

unread,
Mar 7, 2011, 1:48:45 PM3/7/11
to dom...@googlegroups.com
The header/footer is instantiated starting at the current page of the document. Make sure the script is at the top of your body content.

yoga

unread,
Mar 7, 2011, 10:55:50 PM3/7/11
to dompdf
woot.. works like a magic. thanks a lot for your clue.

Ammy

unread,
Mar 31, 2011, 1:22:47 AM3/31/11
to dompdf
Hi,
Can you tell me that where exactly we have to specify this script.
e.g - i have this code within php file. this is giving error while
opening document.

[phpcode]
<?php
require_once('../../pdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
?>
<script type='text/php'>
if ( isset($dompdf) ) {

// Open the object: all drawing commands will
// go to the object instead of the current page
$footer = $dompdf->open_object();
$w = $dompdf->get_width();
$h = $dompdf->get_height();
// Draw a line along the bottom
$y = $h - 2 * $text_height - 24;
$dompdf->line(16, $y, $w - 16, $y, $color, 1);

$img_w = 2 * 72; // 2 inches, in points
$img_h = 1 * 72; // 1 inch, in points -- change these as required
$dompdf->image('di.png', 'png', ($w - $img_w) / 2.0, $y - $img_h,
$img_w, $img_h);

// Close the object (stop capture)
$dompdf->close_object();

// Add the object to every page. You can
// also specify 'odd' or 'even'
$dompdf->add_object($footer, 'all');
}

</script>

<?php
$text=" body text goes here";

$dompdf->load_html($text);
$dompdf->set_paper('a4', 'landscape');
$dompdf->render();
//$dompdf->output();

$dompdf->stream('total.pdf');

[/phpcode]

Martin Thomas Schrott

unread,
Mar 31, 2011, 1:27:58 AM3/31/11
to dom...@googlegroups.com
hi,

place the script below the <body> of your html code.

e.g.
</head>
<body>
---script----
here is the html text that will be shown between your header and footer.
</body>

This way your headers and footers will be shown on every page.

When you place the code below the text, above the </body> tag, it only would
be shown on the last page.

hth
Martin

</script>

$dompdf->stream('total.pdf');

[/phpcode]

--
You received this message because you are subscribed to the Google Groups
"dompdf" group.
To post to this group, send email to dom...@googlegroups.com.
To unsubscribe from this group, send email to
dompdf+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/dompdf?hl=en.


Reply all
Reply to author
Forward
0 new messages