I generate a PDF doc using load_html().
To avoid my footer beiing added on the first page, I'm writing my
inline PHP after the first page code. For exemple
<body>
<div>
My first page
</div>
<p style="page-break-after:always"> </p>
<script type="text/php">
MyPHP
</script>
<div>
Other pages
</div>
I manage to wrote static text and a line by this way. They appear well
on all pages except the first.
But I haven't managed to write the page number.
With : $pdf->text, the {PAGE_NUM} available...
And with $pdf->page_text, it appears on all pages.
Any help?
Regards
Jean
Can you supply the full text of your inline script? You should be
using an object so that the content will propagate to all following
pages. See the FAQ question "How can I add an image to a header or
footer on every page?" for a sample of how to use an object.
http://code.google.com/p/dompdf/wiki/FAQ
<script type='text/php'>
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("verdana", "bold");
$size = 14;
$color = array(0.7,0.7,0.7);
$text_height = Font_Metrics::get_font_height($font, $size);
$w = $pdf->get_width();
$h = $pdf->get_height();
$y = $h - 2 * $text_height - 24;
//$pdf->page_text($w - $width2 - $width-10, $y, $text, $font,
$size, $color);
$foot = $pdf->open_object();
// Draw a line along the bottom
$color = array(0.7,0.7,0.7);
$size = 14;
$width = Font_Metrics::get_text_width('Page', $font, $size);
$pdf->page_text($w - $width, $y, "{PAGE_NUM}" , $font, $size,
$color);
$y += $text_height;
$color = array(0.5,0.5,0.5);
$size = 6;
$text = "BOOK DEVELOPPEMENT DURABLE 2010 _ID LOGISTICS_";
$width2 = Font_Metrics::get_text_width($text, $font, $size);
$pdf->text($w - $width2 - $width-10, $y, $text, $font, $size,
$color);
$pdf->line($w - $width2 - $width-10, $y, $w - $width-10, $y,
$color, 1);
$pdf->close_object();
$pdf->add_object($foot, "all");
}
</script>
This script is included just after the HTML code of the first page.
It works well with line and static text. But not with the page
number...
Regards.
I see where your problem is now. To clarify (for myself), you are
trying to add a page number to ever page but the first. Unfortunately,
DOMPDF can't currently handle this. The page_text() function is
generic and adds the specified text to each page, as you have seen.
The text() function would be more along the lines of what you want,
when used with an object, but it doesn't support the replaceable
strings (e.g. {PAGE_NUM}).
The only work-around I see at present is to add an object (such as a
rectangle) to your first page that hides the page number. Not very
elegant, but there aren't many options otherwise.
-b