【发布时间】:2012-01-16 15:52:31
【问题描述】:
如何在 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 中获取文档的高度和宽度。
例如,我有下一行:
$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');
【讨论】:
现在,您可以简单地调用 GetPageWidth 和 GetPageHeight 方法。
$pdf = new FPDF();
$pdf->addPage("P", "A4");
$pdf->GetPageWidth(); // Width of Current Page
$pdf->GetPageHeight(); // Height of Current Page
【讨论】:
GetPageWidth 返回什么测量值?像素?毫米?厘米?
FPDF 时指定另一个度量来更改它。
装箱需要考虑边距的宽度...
class FPDF_EXTEND extends FPDF
{
public function pageWidth()
{
$width = $this->w;
$leftMargin = $this->lMargin;
$rightMargin = $this->rMargin;
return $width-$rightMargin-$leftMargin;
}
}
【讨论】:
注意:阅读下面罗斯的麦克莱伦的回答
据我记得你不能用香草 FPDF 做到这一点。您可以将其扩展为具有为您返回此值的方法,或者将宽度存储为 fpdf 对象的公共属性。
【讨论】: