Memory exhausted when export to pdf

Topics: Developer Forum, User Forum
Jan 11, 2012 at 5:06 PM
Edited Jan 12, 2012 at 11:58 AM

Hi,

I use 1.7.6, MAC OS, and I get the following error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 65300 bytes) , when i try to convert/export and excel file to pdf. I really don't know what could be the problem. Also I don't have access to php.ini, but it seems that the limit is 64 MB, also the excel (.xls) file is small has one sheet with 20 rows, around 12 KB

below is the code:

 

               $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "PDF");
               //unset($objPHPExcel);
               //ob_end_clean();
               // Redirect output to a client's web browser (pdf)
               header('Content-Type: application/pdf');
               header('Content-Disposition: attachment;filename="pdffile'.date('Ymd_His').'.pdf"');
               header('Cache-Control: max-age=0');
               //$objWriter->writeAllSheets();
               $objWriter->save('test.pdf');
               exit;

I would need some help to escape from this error, and to get the pdf. Thx in advance.

Jan 12, 2012 at 10:48 AM

pls I need some help, I searched trough forum and I read that phpexcel and the pdf exporter eats a lot of memory, is it right, this could be the reason ? because my limit is 64mb as the error says. I first time use it and not so known with all constraints and issues.

Jan 12, 2012 at 10:57 AM

you probably need more memory. 64MB is quite low, even most shared hosting solutions provide higher memory limits.

 

try the following:

 ini_set('memory_limit','256M');

Jan 12, 2012 at 11:42 AM
Edited Jan 12, 2012 at 11:44 AM

thx for your replay still have the problem, I tried 800MB, is very much :

[12-Jan-2012 13:35:41] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 130600 bytes) in /Applications/MAMP/htdocs/wizard/ci_application/my_classes/Classes/PHPExcel/Shared/PDF/tcpdf.php on line 6004[12-Jan-2012 13:37:01] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes) in /Applications/MAMP/htdocs/wizard/ci_application/my_classes/Classes/PHPExcel/Shared/PDF/tcpdf.php on line 18170[12-Jan-2012 13:38:22] PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 77 bytes) in /Applications/MAMP/htdocs/wizard/ci_application/my_classes/Classes/PHPExcel/Shared/PDF/tcpdf.php on line 18021[12-Jan-2012 13:40:46] PHP Fatal error:  Allowed memory size of 838860800 bytes exhausted (tried to allocate 130600 bytes) in /Applications/MAMP/htdocs/wizard/ci_application/my_classes/Classes/PHPExcel/Shared/PDF/tcpdf.php on line 6004

 

and changed on line in code, now is : $objWriter->save('php://output');

Jan 12, 2012 at 11:57 AM
Edited Jan 12, 2012 at 11:57 AM

setuped even 1400mb and changed maximum execution of time for each script to 60 seconds. Now sounds different than a memory problem

Jan 12, 2012 at 12:39 PM
Edited Jan 12, 2012 at 12:41 PM

nevermind, I read too quickly

 

does it only occur if you try to build a pdf? (ie. do other output writers exhibit the same problem?)

Jan 12, 2012 at 1:04 PM
Edited Jan 12, 2012 at 1:20 PM

yes, with the excel and html works perfectly

Jan 12, 2012 at 2:28 PM

solved with excel->html + mpdf -> pdf, and works with 64mb, interesting why tcpdf doesn't work.