Dompdf 0.7.0: counter(pages) is 0

1,751 views
Skip to first unread message

anal...@numerique.ca

unread,
Jun 7, 2016, 10:30:55 AM6/7/16
to dompdf
Dompdf 0.7.0: counter(pages) is 0


<!DOCTYPE HTML PUBLIC>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">

<style type="text/css">
   
#footer{ position: fixed; bottom: 0px; } }
   
#footer:before { content: counter(page) "/" counter(pages); }
</style>
</
head>
<body>
   
<div id="footer">
       
   
</div>
   
    <p>Lorem</
p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p>
   
<p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p>
    <p>Lorem</
p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p>
   
<p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p>
    <p>Lorem</
p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p>
   
<p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p><p>Lorem</p>
</
body>
</html>


lorem.pdf

BrianS

unread,
Jun 7, 2016, 11:48:56 AM6/7/16
to dom...@googlegroups.com
Dompdf does not yet support the pages counter. Until that is implemented the only way to get a page count is to use scripting. You can add the total number of pages using the page_text method to add text a specific location on the page. Something like the following should work:

$dompdf = new Dompdf();
$dompdf
->loadHtml('...');
$dompd
->render();
$fontMetrics
= $dompdf->getFontMetrics();
$canvas
= $this->dompdf->get_canvas();
$font
= $fontMetrics->getFont('Helvetica');
$canvas
->page_text(5, 5, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, 10, array(0, 0, 0));



Or, if you're feeling particularly clever, use the page_script method to replace some templated text in the CPDF object collection. This would allow you to define the layout/styling in HTML/CSS. I don't have time to give a sample for this right now, but if you're interested I can try swing back around later to give you a sample.

Adrien Crivelli

unread,
May 8, 2019, 9:06:21 AM5/8/19
to dompdf
See https://github.com/dompdf/dompdf/issues/1636#issuecomment-490372233 for a proper way to get current and total page and be able to style everything via CSS as usual, which was inspired by BrianS latest comment.
Reply all
Reply to author
Forward
0 new messages