Problems Setting Header Image for "all" pages

1,566 views
Skip to first unread message

ManuX

unread,
Jan 12, 2012, 9:17:08 AM1/12/12
to dompdf
Hi guys!, I'm having problem with header image, I set it and after
render is placed in the right position of the page,but ONLY in last
page... I don't understand why.
I tried creating distinct objectes and ways for create it but always I
get The logo just in last page.
Note: If you see the code, the footer is setted too and it work
perfectly, placed in all pages.

Thanks in Advance!

$html .= '<script type="text/php">
$font = "arial";
//Header
$body = $pdf->open_object();
$x = 25;
$y = 20;
$img_w = 147;
$img_h = 48;
$pdf->image("./css/images/logo.gif", "gif", $x, $y, $img_w,
$img_h);

//Footer
$pdf->page_text(680, 550, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font,
8, array(0,0,0));
$pdf->close_object();
$pdf->add_object($body,"all");
</script>';

$dompdf = new DOMPDF();
$dompdf->set_paper('a4', 'landscape');
$dompdf->load_html($html);
$dompdf->render();

BrianS

unread,
Jan 13, 2012, 12:03:11 PM1/13/12
to dom...@googlegroups.com

When you add header/footer objects using inline script they are placed starting from the page where the script is located. So the way you are generating your header means that it will only appear on the last page. You should modify the code so that the inline script is at the top of the document.

The code you are using to generate your footer does not use an object but a global document string.

I don't know what's in your $html variable, so I can't really tell you how to rewrite your code to address the issue. However, if your $html variable contains a full HTML document, you might rewrite the code to look something like the following:

$script = '
  <script type="text/php">

    $font = "arial";
    //Header
    $body = $pdf->open_object();
    $x = 25;
    $y = 20;
    $img_w = 147;
    $img_h = 48;
    $pdf->image("./css/images/logo.gif", "gif", $x, $y, $img_w, $img_h);
    $pdf->close_object();
    $pdf->add_object($body,"all");

    //Footer
    $pdf->page_text(680, 550, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, array(0,0,0));
  </script>';

$html = str_replace('<body>', '<body>'.$script, $html);

ManuX

unread,
Jan 19, 2012, 8:11:12 PM1/19/12
to dompdf
Hi BrianS, I make the change but it didn't work.
Also if I put my code at start of body tag I don't see anymore the
footer that was working well.
I tryed putting my code at starting of <head> and before <html> but
anything...

Some Idea?

Thanks!

ManuX

unread,
Jan 19, 2012, 8:25:44 PM1/19/12
to dompdf
I think that the problem could be related with the Object that I'm
creanting because if I put the $pdf->image(); without the object at
the end like footer I see the image in last page too... I mean, work
for last page with or without object only if put my code at the end of
hatm code, still not working at the start of <body> tag.

On Jan 13, 2:03 pm, BrianS <eclecticg...@gmail.com> wrote:

BrianS

unread,
Jan 20, 2012, 9:20:48 PM1/20/12
to dom...@googlegroups.com
It would help to see the HTML instead of the PHP that creates the HTML. What is probably happening is that the inline script is not contained within the body of the HTML document. In the situation dompdf will ignore the scripts. Inline script must currently appear within the body of the document.


On Thursday, January 19, 2012 8:11:12 PM UTC-5, ManuX wrote:
Hi BrianS, I make the change but it didn't work.
Also if I put my code at start of body tag I don't see anymore the
footer that was working well.
I tryed putting my code at starting of <head> and before <html> but
anything...

Some Idea?

Thanks!

ManuX

unread,
Jan 21, 2012, 6:36:58 PM1/21/12
to dompdf
Hey Brian!
I fix my problem, stupid mistake when I generate the pdf...
Your solution work great!

Thanks I really appreciate your help :)
Reply all
Reply to author
Forward
0 new messages