page numbers

122 views
Skip to first unread message

Jon

unread,
Feb 21, 2012, 8:32:31 PM2/21/12
to dompdf
I cannot seem to figure out how to get page numbers working.

I set the constant DOMPDF_ENABLE_PHP to true. Then, I have been
trying to use the example on this page: http://code.google.com/p/dompdf/wiki/FAQ
. It just isnt working. Is there an example of a working document
with page numbers that I can see somewhere?

Here is my code:
<?php
require_once("../../libraries/dompdf/dompdf_config.inc.php");

$html = '
<html>
<head>
<script type="text/php">

if ( isset($pdf) ) {

$font = Font_Metrics::get_font("helvetica", "bold");
$pdf->page_text(72, 18, "Header: {PAGE_NUM} of
{PAGE_COUNT}", $font, 6, array(0,0,0));

}
</script>
</head>
<body>
my document here...
</body>
</html>';

$dompdf = new DOMPDF();
$dompdf->set_paper("a4", "landscape" );
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));

?>

BrianS

unread,
Feb 23, 2012, 1:52:26 PM2/23/12
to dom...@googlegroups.com

Currently dompdf requires that any inline script be located in the BODY of the document. So your code should look like the following:

<?php
require_once("../../libraries/dompdf/dompdf_config.inc.php");

$html = '
<html>
<body>

<script type="text/php">
if ( isset($pdf) ) {
  $font = Font_Metrics::get_font("helvetica", "bold");
  $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
}
</script>
my document here...
</body>
</html>';

$dompdf = new DOMPDF();
$dompdf->set_paper("a4", "landscape" );
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
?>
Reply all
Reply to author
Forward
0 new messages