AddPage();
$pdf->SetFont(‘Arial’, ”, 12);
$pdf->writeHTML($text);
$pdfContent = $pdf->Output(”, ‘S’);
// Convert text to JPG
$im = imagecreatetruecolor(400, 300);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 299, $white);
$font = ‘arial.ttf’;
imagettftext($im, 20, 0, 10, 50, $black, $font, $text);
ob_start();
imagejpeg($im);
$jpgContent = ob_get_clean();
imagedestroy($im);
// Offer Download Links
$pdfName = “text_as_pdf.pdf”;
$jpgName = “text_as_jpg.jpg”;
file_put_contents($pdfName, $pdfContent);
file_put_contents($jpgName, $jpgContent);
?>