How can FPDF be used to avoid widows and orphans, such as in the case of Multicell?

To avoid widows and orphans when using FPDF's Multicell function, you can set the line height to ensure that the last line of a paragraph is not split between two pages. This can be achieved by calculating the remaining space on the page and adjusting the line height accordingly.

// Calculate remaining space on the page
$remaining_space = $pdf->h - $pdf->GetY();

// Check if there is enough space for the next line
if ($remaining_space < $line_height) {
    $pdf->Ln($line_height - $remaining_space); // Adjust line height to avoid widow/orphan
}

$pdf->Multicell($width, $height, $text);