我已经成功实施了dompdf来生成PDF文件。现在我 想要在页脚中添加分页,但我希望该页码以>开头第2页,因为在第一页我放置封面图像所以计数应从第2页开始如何自定义此代码
$pdf->page_text(500,10, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 6,array(0,0,0));
因为这会在所有页面上开始分页,但我不想包含 第一页。
答案 0 :(得分:1)
对于页码,只需添加几行代码:
$pdf=$dompdf->get_canvas();
if ( isset($pdf) ) {
$pdf->page_script('
if ($PAGE_NUM > 1) {
$PAGE_NUM=$PAGE_NUM-1;
$PAGE_COUNT=$PAGE_COUNT-1;
$font = Font_Metrics::get_font("Arial, Helvetica, sans-serif", "normal");
$size = 12;
$pageText1 = " Page " ;
$y1 = $pdf->get_height() - 34;
$x1 = $pdf->get_width() - 15 - Font_Metrics::get_text_width($pageText1, $font, $size);
$pdf->text($x1, $y1, $pageText1, $font, $size);
$pageText = $PAGE_NUM . " of " . $PAGE_COUNT;
$y = $pdf->get_height() - 20;
$x = $pdf->get_width() - 15 - Font_Metrics::get_text_width($pageText, $font, $size);
$pdf->text($x, $y, $pageText, $font, $size);
}
');
}