Search code examples
fpdf

Keeping track of text position on pdf using FPDF and GetY


I am trying to keep track of the current Y position on a PDF page created using FPDF so that I can correctly start a new page ensuring tables do not cross a page break. Firstly am I right in using GetY to monitor this and if so what is the correct syntax. I am trying

$currentYposition = GetY();

but it does not seem to work. Any advice?


Solution

  • No idea why this works - but it does: If you just grab Y after the call, it seems to be the value before the MultiCell. Grabbing it before and after and taking the difference gives you the height.

    $oldY = $this->getY();
    $this->MultiCell(150, 4, utf8_decode($description), 0, "L");
    $newY = $this->getY();
    
    $multiCellHeight = $newY-$oldY;