I tried using Jay's answer and it worked for the intended purpose but for some reason caused my logo to not appear after the first page. I didn't want to do an in depth analysis, but had something to do with the cloning. I then tried the same approach, but using transactions. This produced hundreds of errors.
Then I came up with this rather simple solution using the same object.
/**
* Gets an accurate measurement of a cell's rendered height.
*
* @param float $width the width of the column to be rendered
* @param string $contents the contents to be rendered
*
* @return float
*/
private function getCellHeight(float $width, string $contents): float
{
$view = $this->view;
$currentPage = $view->getPage();
$currentX = $view->GetX();
$currentY = $view->GetY();
$view->AddPage();
$x = $view->GetX();
$start = $view->GetY();
$view->writeHTMLCell($width, 15, $x, $start, $contents, self::INSTANCE_BORDER, 1);
$height = $view->GetY() - $start;
$view->deletePage($view->getPage());
$view->setPage($currentPage);
$view->changePosition($currentX, $currentY);
return $height;
}
As the writeHTMLCell
function requires a $h
, I use 15
, but it can be anything you want, as can the $border
value.
The $ln
value needs to be set to 1
, otherwise the y
value resets before the GetY()
can get it.
changePosition
is my own wrapper for SetXY()
.