Skip to content

Instantly share code, notes, and snippets.

$text = "This is an an example of a MultiCell";
$h = 14; $w = 28; // Height and width for cells
$spaceleft = $pdf->h - $pdf->GetY() - $pdf->bMargin // Calculates the space available on the current page
$multiCellHeight = $pdf->GetMultiCellHeight($w, $h, $text); // Calculates what the height of your MultiCell would be
if ($multiCellHeight > $spaceleft) {
$pdf->AddPage() // Adds a page if there is not enough space available for the MultiCell
}
@johnballantyne
johnballantyne / gist:4089627
Created November 16, 2012 18:22
GetMultiCellHeight() script for FPDF
function GetMultiCellHeight($w, $h, $txt, $border=null, $align='J') {
// Calculate MultiCell with automatic or explicit line breaks height
// $border is un-used, but I kept it in the parameters to keep the call
// to this function consistent with MultiCell()
$cw = &$this->CurrentFont['cw'];
if($w==0)
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
$s = str_replace("\r",'',$txt);
$nb = strlen($s);