![](/img/trans.png)
[英]How to show DOMPDF footer - Page number and Page count in all pages except last page
[英]dompdf a way to remove the footer on the last page?
使用DOMPDF 0.6.0 beta 3,我嘗試構建一個pdf,其中包含可變數量的文本頁面,后面是填充了客戶端徽標的最后一頁。 我想在除了最后一頁之外的所有頁面上都有一個圖片。
我現在使用它,並在所有頁面上添加頁腳,包括最后一頁:
$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()可以接收(所有,添加,奇數,偶數)參數,但我看不到可以控制最后一頁的內容。
我嘗試使用$ PAGE_NUM和$ PAGE_COUNT檢查它們是否相等,這意味着我在最后一頁並在那里做一些事情。 但每次$ PAGE_NUM和$ PAGE_COUNT都會返回1。
有關如何刪除最后一頁頁腳的任何想法?
謝謝。
試試這個:
<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.