How to display page count in footer with 0.6 beta

1,701 views
Skip to first unread message

uk

unread,
Apr 5, 2011, 4:49:16 AM4/5/11
to dompdf
Hi.

I want to set a footer as in the version before with a page count,
current date ...

I´m using the latest 0.6 beta 2.

What I want to display is:
- a solid line from left to right
- on the left a url
- on the right the current date and a page count like "page 1 of 4"

I can only not realis the page count in PHP. How can I do that with
the current version?

Martin Thomas Schrott

unread,
Apr 5, 2011, 8:16:46 AM4/5/11
to dom...@googlegroups.com
Hi,

just put a script like the one below at the beginning of your html body.
(you may remove the \ signs, I need them because of perl)

<script type="text/php">

if ( isset(\$pdf) ) {

\$w = \$pdf->get_width();

\$h = \$pdf->get_height();

\$font = Font_Metrics::get_font("helvetica", "bold");

\$size = 10;

\$text = "Seite: {PAGE_NUM} / {PAGE_COUNT}";

\$width = Font_Metrics::get_text_width("Seite: xxxx/xxxx", \$font, \$size);

// add page number on the bottom middle of the page

\$pdf->page_text((\$w - \$width), 16, \$text, \$font, \$size, array(0,0,0));

}

</script>

hope this helps,

Martin


Hi.

--
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.


uk

unread,
Apr 5, 2011, 8:32:27 AM4/5/11
to dompdf
Thanks, but I do this at the moment and since I now use dompdf 0.6.0
beta 2, the footer dropped away. This code above seems not to work at
the moment or something changed so that it is not displayed. I have to
test a little bit.

Daniele

unread,
Apr 8, 2011, 4:34:30 AM4/8/11
to dompdf
Hi!

I have the same problem, I tried every snippet I found on the site to
add page count but nothing, it simply seems to ignore the
instructions.
uk, do you have found a way to solve the problem?

Thanks!

Daniele

Daniele

unread,
Apr 8, 2011, 4:36:31 AM4/8/11
to dom...@googlegroups.com
Hi!

I have exactly the same issue; I tried the code posted by Martin but it didn't work.
Does anyone have a solution?

Thanks!

Daniele

uk

unread,
Apr 8, 2011, 5:04:45 AM4/8/11
to dompdf
I opened an issue.

Fabien Ménager

unread,
Apr 8, 2011, 6:55:18 AM4/8/11
to dom...@googlegroups.com
See the CSS > content example here :


See the source code of the HTML file :


It is using CSS Generated content. The main issue with this right now is that is doesn't support the page count, only the current page number, but you can display it in roman, upper-roman, greek, etc

uk

unread,
Apr 19, 2011, 10:04:15 AM4/19/11
to dompdf
Thanks very much.
I don´t try the HTML/CSS variant, I just enabled inline PHP. For me it
´s okay, because I´m working in a closed system.

If someone has as well no security reasons, it can be enabled here:
dompdf/dompdf_conf_inc.php > def("DOMPDF_ENABLE_PHP", true);
(~ line 309)

BrianS

unread,
Apr 21, 2011, 3:44:06 PM4/21/11
to dom...@googlegroups.com
FYI, also remember to place your script inside the <body> element. Currently DOMPDF does not process script in the <head>.

eggsurplus

unread,
May 4, 2011, 2:36:02 AM5/4/11
to dom...@googlegroups.com
Placing in the <body> element did the trick for me. I did not include the html/head/body tags at all. As soon as I added them the header worked.

Thanks.
Reply all
Reply to author
Forward
0 new messages