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);
You can just use $pdf->GetY(); to get the curent y value. Then when you have printed all the text, you can use $pdf->GetY(); to get the height after each piece of text.
Adding Image to PDF file by FPDF php'); $pdf = new FPDF(); $pdf->AddPage(); $pdf->Image('images/pdf-header. jpg',0,0); $pdf->Output(); ?> The ouput of above code is here . ( Show Output ) We can add position with height, width and link to above code.
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');
Nowadasy, you can simply call GetPageWidth
and GetPageHeight
methods.
$pdf = new FPDF();
$pdf->addPage("P", "A4");
$pdf->GetPageWidth(); // Width of Current Page
$pdf->GetPageHeight(); // Height of Current Page
Encase someone needs to get the width taking margins into consideration...
class FPDF_EXTEND extends FPDF
{
public function pageWidth()
{
$width = $this->w;
$leftMargin = $this->lMargin;
$rightMargin = $this->rMargin;
return $width-$rightMargin-$leftMargin;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With