I recently installed dompdf 0.83 and have been able to generate documents successfully. However, I am struggling to create a footer that displays the page number out of the total number of pages. Both css and script methods have not been effective for me so far. When attempting to use a script, I encountered an error stating that "$PAGE_COUNT" is an unknown variable.
Although I was able to get the current page number using both css and script, I have not been able to figure out how to display the total number of pages. I have tried numerous examples without success.
<?php require_once "dompdf/autoload.inc.php";
use Dompdf\Dompdf;
use Dompdf\Options;
$options = new Options();
$options->set('defaultFont', 'Courier');
$dompdf = new Dompdf($options);
$html='
<html>
<head>
<style>#footer { position: fixed; right: 0px; bottom: 10px; text-align: center;border-top: 1px solid black;}
#footer .page:after { content: counter(page, decimal) " osssf "counter(pages, decimal); }
@page { margin: 20px 30px 40px 50px; }</style>
</head>
<body>
<div id="footer">
<script type="text/php">
if (isset($pdf))
{
$x = 72;
$y = 18;
$text = "{PAGE_NUM} of {PAGE_COUNT}";
$font = $fontMetrics->get_font("helvetica", "bold");
$size = 6;
$color = array(255,0,0);
$word_space = 0.0; // default
$char_space = 0.0; // default
$angle = 0.0; // default
$pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
}
</script>Peep '.$PAGE_COUNT.'
</div> </body></html>';
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper("A4", "portrait");
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf ->stream();
?>