Skip to content

Instantly share code, notes, and snippets.

@johnballantyne
Created October 21, 2014 16:05
Show Gist options
  • Save johnballantyne/2989898e2196686388f6 to your computer and use it in GitHub Desktop.
Save johnballantyne/2989898e2196686388f6 to your computer and use it in GitHub Desktop.
$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
}
$pdf->MultiCell($w, $h, $text); //Adds the MultiCell
@johnballantyne
Copy link
Author

If you want MultiCells to be "self aware" and automatically create a new page if they're too big, you could modify the core MultiCell() function.

A quick and dirty way to do it would be to call my GetMultiCellHeight() method from within MultiCell() and add the above logic. A better way might be to merge the two methods so that it's more efficient as I'm sure there would be some redundancy.

Modifying core methods can be risky, so it'd be wise to copy MultiCell() and call the new one something like SmartMultiCell()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment