How do I get the width and height of a doc generated with FPDF

chenio picture chenio · Jan 16, 2012 · Viewed 31.2k times · Source

How can I get height and width of a document in FPDF.

For example, I've next line:

$this->Cell(200,5,'ATHLETIC DE COLOMBIA S.A.',1,1,'C',1);

But, I want to do something like:

// $x = width of page
$this->Cell($x,5,'ATHLETIC DE COLOMBIA S.A.',1,1,'C',1);

Answer

Ross McLellan picture Ross McLellan · Oct 11, 2012

Needed to do this myself so was just checking the most recent version of FPDF and it looks like the width & height are already available as public properties. So for anyone looking for the same info:

$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');