The accepted answer works for non-colored backgrounds. If, you wanted to have colored backgrounds, then the accepted answer wouldn't shade the smaller height columns properly.
The below code provides the same functionality as the approved answer, but also supports colored backgrounds. It may not be the cleanest solution (because it has to render the MultiCell components twice), but is the only solution I could create that actually works:
function MultiCellRow($pdf, $data, $width, $height,$darkenBackground){
$x = $pdf->GetX();
$y = $pdf->GetY();
$maxheight = 0;
for ($i = 0; $i < count($data); $i++) {
$pdf->MultiCell($width, $height, $data[$i],0,'C');
if ($pdf->GetY() - $y > $maxheight) $maxheight = $pdf->GetY() - $y;
$pdf->SetXY($x + ($width * ($i + 1)), $y);
}
for ($i = 0; $i < count($data); $i++) {
if($darkenBackground) $pdf->Rect($x+$width*$i,$y,$width,$maxheight,"F");
$pdf->Line($x + $width * $i, $y, $x + $width * $i, $y + $maxheight);
$pdf->SetXY($x+$i*$width,$y);
$pdf->MultiCell($width, $height, $data[$i],0,'C');
}
$pdf->Line($x + $width * count($data), $y, $x + $width * count($data), $y + $maxheight);
$pdf->Line($x, $y, $x + $width * count($data), $y);
$pdf->Line($x, $y + $maxheight, $x + $width * count($data), $y + $maxheight);
$pdf->SetY($y+$maxheight);}
Where the inputs are:
$pdf
is the pdf object (new FPDF();)
$data
is the array of strings to be rendered in the row
$width
is the cell width (integer)
$height
is determines the padding/line-spacing of the cell
$darkenBackground
is a Boolean.
I give partial credit to "Florian7843" for the first half of the code. I would have edited their existing post, but I made significant changes and thought it would be better to contribute a separate answer.
If somebody wants to dedicate a cleaner/efficient solution, please propose an edit.
Cheers!