DOMPDF(0.8.3):跳过具有标题的第一页

时间:2019-08-26 13:42:22

标签: php laravel dompdf export-to-pdf

我正在使用dompdf版本0.8.3。我们在每个页面中都添加了一些标题,但我们希望标题仅出现在第二页以后。

我们现在拥有的是每页上都有页眉和页脚,但是当页面从第二页开始时,我们想显示'P O#:number?>

控制器

<!-- My other function/data -->
$pdf = PDF::loadView('purchase-order.export.export-pdf', $data)->setPaper('a4');
$pdf->getDomPDF()->set_option("enable_php", true);
return $pdf->stream('purchase-order-'.$purchase_order->number.'.pdf');

PDF

<style type="text/css">
    @page {
            margin-top: 40px !important;
            margin-bottom: 50px !important;
        }
</style>
<div class="page-break">
    <div id="page-wrap">
        <script type="text/php">
            if (isset($pdf)) {
                $x = 25;
                $y = 800;
                $text = "page {PAGE_NUM} of {PAGE_COUNT}";
                $page_num = "{PAGE_NUM}";
                $text2 = "This is a system generated document";
                $font = 'Arial';
                $size = 11;
                $color = array(0.333,0.333,0.333);
                $word_space = 0.0;  //  default
                $char_space = 0.0;  //  default
                $angle = 0.0;   //  default
                // header
                $pdf->page_text(500,10,'P O #: <?= $purchase_order->number ?>',$font,$size,$color,$word_space,$char_space,$angle);
                // footer
                $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
                // generated
                $pdf->page_text(410, $y, $text2, $font, $size, $color, $word_space, $char_space, $angle);
            }
        </script>
    </div>
</div>

问题:是否可以跳过第一页以获得标题?

1 个答案:

答案 0 :(得分:0)

如果我的回答正确,我相信您想跳过第一页,在第二页上显示页眉,页脚和生成的文本,依此类推。您可以添加条件以检查当前页面是什么,然后仅在该页面大于1时显示页眉分页:

if ($page_num > 1) {
  // header
  $pdf->page_text(500,10,'P O #: <?= $purchase_order->number ?>',$font,$size,$color,$word_space,$char_space,$angle);
  // footer
  $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
  // generated
  $pdf->page_text(410, $y, $text2, $font, $size, $color, $word_space, $char_space, $angle);
}