How can one efficiently buffer the output of fpdf's Output() function for email sending?

When using fpdf's Output() function to generate a PDF for email sending, you can efficiently buffer the output by using ob_start() and ob_get_clean() functions. This allows you to capture the PDF output without directly sending it to the browser, making it easier to attach to an email.

<?php
// Start output buffering
ob_start();

// Generate PDF using fpdf's Output() function
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();

// Get buffered output and clear buffer
$pdf_content = ob_get_clean();

// Now you can attach $pdf_content to an email
?>