Question

I have an important html file to convert into a PDF file.

I use mpdf to convert my HTML like this:

$file_content = file_get_contents($dir . '/' . $filehtml);
$mpdf = new mPDF('', '', 0, 'Helvetica', 15, 15, 50, 25, 8, 8);
$mpdf->useSubstitutions = false;
$mpdf->CSSselectMedia='mpdf';

$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'cp1252';
$mpdf->WriteHTML($file_content);
$mpdf->Output($dir . '/' . $filename, 'F');

It works well. Usually.

Problem is that my file is pretty heavy : ~17.5Mb, so file_get_contents throws me an error :

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 18114800 bytes)

I tried another solution : Instead of generate an HTML file, I tried to put $mpdf->WriteHTML($str); into the foreach() (which is used to generate my HTML file).

Problem is execution time goes over 1hour, which is definitly not acceptable, while generating HTML files takes me ~1.5sec (according to js new Date().getTime();)


Does anyone has a server-side solution for this kind of problem?

Was it helpful?

Solution

change in php.ini

memory_limit = 64M ;//maximum allotted size

if there is no php.ini access to you then add in .htaccess

php_value memory_limit 64M

or add below line in your script file

ini_set('memory_limit', '-1');

OTHER TIPS

Try to add this in your .htaccess file : php_value memory_limit 128M

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top