<script type="text/php">
if ( isset($pdf) )
{
$font = Font_Metrics::get_font("verdana");
// If verdana isn't available, we'll use sans-serif.
if (!isset($font)) { Font_Metrics::get_font("sans-serif"); }
$size = 14;
$color = array(0,0,0);
$text_height = Font_Metrics::get_font_height($font, $size);
$w = $pdf->get_width();
$h = $pdf->get_height();
// ------------------ FOOTER ------------------------------------------
if ($PAGE_NUM > 1)
{
$footer = $pdf->open_object();
$y = $h - 3 * $text_height - 24;
$text = "Seite {PAGE_NUM}"; //"Page {PAGE_NUM} of {PAGE_COUNT}";
$width = Font_Metrics::get_text_width("Seite 100", $font, $size);
$pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
// Copyright line
$y += $text_height * 2;
$text = $pdf->get_page_number() . "Urheberrechtlich geschützt. Geschrieben und veröffentlicht auf www.wrible.com";
// Center the text
$width = Font_Metrics::get_text_width($text, $font, $size);
$pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
// Add a logo
$img_w = 0.5 * 72; // 0,5 inches, in points
$img_h = 0.5 * 72; // 0,5 inch, in points -- change these as required
//$pdf->image("http://localhost/elgg-1.7.4/mod/writersdesk/templates/print_logo.png", "png", 0, $y, $img_w, $img_h);
$pdf->close_object();
$pdf->add_object($footer, "all");
}
// ------------------ FOOTER END ------------------------------------------
}
</script>
something additional... If you did not realice it in the meantime.
Inline scripts have two different options:
place it on the end of your body tag and it only will be rendered for the
last page.
Place it anywhere between the beginning of your body tag and the end and it
will be rendered from its position on all following pages. e.g. on the
beginning of the body tag it will be rendered on all pages beginning with
page 1.
this in mind you will be more flexible I guess.
cheers
Hi,
WHY ?
thanks,
nick
--
thanks for this, but my problem is actually more complex i guess.
i want to explicitly say on which pages the script gets rendered not on ALL
pages
or just the LAST page.
having $PAGE_NUM and an if statement and the option "ADD" with the
add_object
you should be able to just
SKIP PAGE 1
which is what i need to do.
thanks,
nick
-----Urspr�ngliche Nachricht-----
From: Martin Thomas Schrott
Sent: Wednesday, May 04, 2011 9:35 AM
To: dom...@googlegroups.com
Subject: Re: [dompdf] Inline PHP
however the one thing that’s not working with the inline script is that it only gets called one time(first or last page)is you have a text() inside the php script this gets only called one time.in my understanding it should be called every page (inside the renderer class) or am i missing something ?
i fixed the issue for me but a strange thing i’m encountering is that when i add an image with my techniquethe whole text on every page where the image is, gets blurry and somehow bolder.it seems that reopening the pages and adding the script to every page (adding an image) somehow breaksthe nice looking of the font of the page, can that be ?
the image error could be solved by converting the png file into an gif, seems like a problem with png.maybe only png with dpi 300x300 and RGB 32bit color space.i haven’t tried yet converting the png to 72dpi indexed color, maybe then it works...
actually you are right with the add_object, if you specify “all” for the second parameter it gets added to every page.at the beginning of my post i mentioned that i only want to draw on specific pages using the “add” parameterfor add_object. but this only outputs on the first page, because the renderer looks up the script and executesit only one time.
(the page_script reopens every page and processes the script on every page, there you can check with PAGE_NUMon which page to draw)however it would be nice if the add_object($pid, “add”) would also work, but it’s not necessary for me right now.i think you would have to pick up the script in renderer and then when there is a new page, call every script that youhave found.
first of all the image problem is not there with pdflib (pdflib currently not working i have posted issue).
but:both cpdf and pdflib produce the following problem with my script for footer and header. (or page_text)if for example i have a green color in the text on 2 pages. (end of first page beginning of second page)then the text in between (the header or footer for example) also gets green, although i specified setcolor blackin the script, so actually as the header or footer seems to be inside the “span” of the green text, the colorgets overriden, which of course is not what i want.the problem is with reopening the object after rendering the pages ?you can try it very quick and simple, make html text green over 2 pages, add a php/script with page_text(appears on every page) colored black –> but it will get green.Reopening Objects VS Adding new ones:if you use just $pdf->text instead of $pdf->page_text,create an object and add it to every page (add_object($pid, “all”)), then it gets colored black, so then it is working.So I cannot use my technique no more, i really have to put the footer and header rendering inside the renderprocess where objects gets added to pages. (but not to all pages, to just specific ones (script has to getexecuted on every page ( if i specifiy add_object($pid, “add”))“we need a way to dynamically (script) add objects to specific pages.”