FPDF在每个A4尺寸页面的页脚处获取页码 [英] FPDF Get page numbers at footer on Every A4 size page
本文介绍了FPDF在每个A4尺寸页面的页脚处获取页码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用FPDF创建PDF报告.现在,如何在页面底部的报表的每一页上生成页码. 下面是生成两页PDF的示例代码.
I am creating PDF reports using FPDF. Now how do I generate page numbers on each page of a report at the bottom of the page. Below is the sample code for generating a 2 page PDF.
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','',16);
$start_x=$pdf->GetX();
$current_y = $pdf->GetY();
$current_x = $pdf->GetX();
$cell_width = 25; $cell_height=14;
$j = 20; // This value will be coming from Database so we dont know how many pages the report is going to be
for ($i = 0; $i<$j ; $i++){
$pdf->MultiCell($cell_width,$cell_height,'Hello1',1);
$current_x+=$cell_width;
$pdf->Ln();
}
$pdf->Output();
?>
注意:$ j值将来自数据库,因此我们不知道报告将要包含多少页.
Note : The $j value will be coming from the database so we don't know how many pages is the report going to be.
推荐答案
要添加纵向的A4页面,请执行以下操作:
To add an A4 page, with portrait orientation, do:
$pdf->AddPage("P","A4");
创建一个扩展FPDF
类的新类,并覆盖预定义的Footer
方法.
Create a new class which extends the FPDF
class, and override the pre-defined Footer
method.
示例:
class PDF extends FPDF
{
function Footer()
{
// Go to 1.5 cm from bottom
$this->SetY(-15);
// Select Arial italic 8
$this->SetFont('Arial','I',8);
// Print centered page number
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
}
这篇关于FPDF在每个A4尺寸页面的页脚处获取页码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文