页脚与页码

时间:2019-08-22 14:56:46

标签: css dompdf

我刚刚下载了dompdf 0.83。生成工作正常。我想要的页脚类似:第1页,共10页。 css均不起作用,也没有脚本版本。使用脚本时,出现错误,未知变量“ $ PAGE_COUNT”。

使用CSS,我得到了实际的数字(与脚本相同),但没有页面总数。我整理了成千上万的eambels,都没有用。

<?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();
?>
$ PAGE_Num工作正常。即使是css。怎么了? 问候 海啸

1 个答案:

答案 0 :(得分:0)

我想,错误“未知变量$ PAGE_COUNT”是由于此行中的$PAGE_COUNT.而引起的:

</script>Peep '.$PAGE_COUNT.'

在我的情况下,$text = "page {PAGE_NUM} of {PAGE_COUNT}";中的$pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);if ( isset($pdf) ) { ... }足以使分页工作。