What are best practices for handling special characters like apostrophes in PHP when generating PDFs with FPDF?

Special characters like apostrophes can cause issues when generating PDFs with FPDF in PHP if not properly handled. To ensure these characters are displayed correctly, it is recommended to use UTF-8 encoding and escape special characters using the `addslashes()` function before passing them to FPDF functions.

// Set UTF-8 encoding
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',12);

// Escape special characters
$text = "It's a special character";
$text = addslashes($text);

// Output text
$pdf->Cell(0, 10, $text, 0, 1);

$pdf->Output();