Open arvindpdmn opened 3 years ago
mpdf could be considered:
Limitations:
Some trial code:
$text = $content->getBody();
$text = str_replace("/images/", "images/", $text);
$text = preg_replace('/src="(.*?)" data-fullsrc="(.*?)"/', 'src="\2" data-fullsrc="\2"', $text);
$text = preg_replace('/<body class=/', '<body style="margin-left:80px" class=', $text);
$text = preg_replace('/<div class="article-middle/', '<div style="margin-left:80px" class="article-middle', $text);
$text = preg_replace('/<figure class=/', '<figure style="border:0px" class=', $text);
$mpdf = new Mpdf([
'mode' => 'utf-8',
'format' => 'A4-P',
'orientation' => 'P'
]);
//$mpdf->showImageErrors = true;
$mpdf->WriteHTML($text);
$mpdf->Output('download.pdf', 'F');
Tried dompdf package but mpdf seems to be better:
$dompdf = new Dompdf();
$dompdf->loadHtml($text);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
file_put_contents("download.pdf", $dompdf->output());
As in title. Inspired by this feature in Wikipedia.