What are some common pitfalls when using FPDF to generate PDFs in PHP?

One common pitfall when using FPDF is not setting the proper content type header before outputting the PDF, which can result in corrupted files. To solve this, make sure to set the header using header('Content-Type: application/pdf') before outputting any content with FPDF.

// Set content type header
header('Content-Type: application/pdf');

// Create FPDF object
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(40, 10, 'Hello World!');

// Output PDF
$pdf->Output();