简体   繁体   English

dompdf一种删除最后一页页脚的方法?

[英]dompdf a way to remove the footer on the last page?

Using DOMPDF 0.6.0 beta 3, I try to build a pdf with a variable number of text pages followed by a last page that is filled with clients logos. 使用DOMPDF 0.6.0 beta 3,我尝试构建一个pdf,其中包含可变数量的文本页面,后面是填充了客户端徽标的最后一页。 I want to have a image in the footer on all the pages except the last one. 我想在除了最后一页之外的所有页面上都有一个图片。

I use this for now, and it adds the footer on all the pages including the last one: 我现在使用它,并在所有页面上添加页脚,包括最后一页:

  $footer = $pdf->open_object();

  $w = $pdf->get_width();
  $h = $pdf->get_height();

  $y = $h - 2 * $text_height - 24;

  $img_w = 590; 
  $img_h = 170; 
  $pdf->image("footer-pdf.png", ($w - $img_w) / 2.0, $y - $img_h, $img_w, $img_h);

  $pdf->close_object();

  $pdf->add_object($footer, "all");

add_object() can receive the (all, add, odd, even) parameters but i can't see something that can control the last page. add_object()可以接收(所有,添加,奇数,偶数)参数,但我看不到可以控制最后一页的内容。

I tried using the $PAGE_NUM and $PAGE_COUNT to check if they are equal it means i am on the last page and do some stuff there. 我尝试使用$ PAGE_NUM和$ PAGE_COUNT检查它们是否相等,这意味着我在最后一页并在那里做一些事情。 But both $PAGE_NUM and $PAGE_COUNT return 1 everytime. 但每次$ PAGE_NUM和$ PAGE_COUNT都会返回1。

Any idea on how to remove the footer on the last page? 有关如何删除最后一页页脚的任何想法?

Thank you. 谢谢。

Try this: 试试这个:

 <script type="text/php">
if ( isset($pdf) ) { 
    $pdf->page_script('
        if ($PAGE_COUNT > 1 && $PAGE_NUM!=$PAGE_COUNT ) {
            $font = Font_Metrics::get_font("helvetica", "normal");
            $size = 9;
            $pageText = "Page " . $PAGE_NUM . " of " . $PAGE_COUNT;
            $y = $pdf->get_height() - 24;
            $x = ($pdf->get_width() /2) - ( Font_Metrics::get_text_width($pageText, $font, $size) / 2);
            $pdf->text($x, $y, $pageText, $font, $size);
        } 
   ');
}   
 </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM