如何在FPDF中获取文档的高度和宽度。
例如,我有下一行:
$this->Cell(200,5,'ATHLETIC DE COLOMBIA S.A.',1,1,'C',1);
但是,我想做一些类似的事情:
// $x = width of page
$this->Cell($x,5,'ATHLETIC DE COLOMBIA S.A.',1,1,'C',1);
我需要自己做这件事,所以我只是检查了FPDF的最新版本,它看起来像是宽度&高度已作为公共属性可用。因此,对于任何寻找相同信息的人来说:
$pdf = new FPDF();
$pdf->addPage("P", "A4");
$pdf -> w; // Width of Current Page
$pdf -> h; // Height of Current Page
$pdf -> Line(0, 0, $pdf -> w, $pdf -> h);
$pdf -> Line($pdf -> w, 0, 0, $pdf -> h);
$pdf->Output('mypdf.pdf', 'I');
更新:2017年11月
现在,您可以简单地调用GetPageWidth
和GetPageHeight
方法。
$pdf = new FPDF();
$pdf->addPage("P", "A4");
$pdf->GetPageWidth(); // Width of Current Page
$pdf->GetPageHeight(); // Height of Current Page
Encase某人需要获得考虑边距的宽度。。。
class FPDF_EXTEND extends FPDF
{
public function pageWidth()
{
$width = $this->w;
$leftMargin = $this->lMargin;
$rightMargin = $this->rMargin;
return $width-$rightMargin-$leftMargin;
}
}
注意:阅读下面Ross’McLellan的答案
据我记忆所及,香草FPDF是做不到的。您可以将其扩展为具有一个为您返回此值的方法,也可以将宽度存储为fpdf对象的公共属性。