PDF to B64 using mPDF

Viewed 1130

I'm using the mPDF library to convert a html into a PDF file. But i need an extra step and that is converting the PDF file to base64. Currently I have this co:

require_once('lib/mpdf.php');

$mpdf = new mPDF('c','A4');
$mpdf->writeHTML('<div>"Hello Wolrd!!"</div>');

echo base64_encode($mpdf);

The require is for the mPDF library, then I create the pdf file and I0m trying to convert it into base 64 but the $mpdf variable is not a string so the function base64_encode is not working. Can someone help me with this. Thanks

1 Answers

Try below:

require_once('lib/mpdf.php');

$mpdf = new mPDF('c','A4');
$mpdf->writeHTML('<div>"Hello Wolrd!!"</div>');

echo base64_encode($mpdf->Output('', 'S'));

By the way, you should upgrade to the recent Mpdf 8.0 if possible. It looks like you're using an old version.

Related