tags:

views:

110

answers:

5

This is a often discussed issue but so far no solution seems to fit for my problem. I'm generating a pdf with $pdf = new FPDF(); . This works fine. But now I want to have a footer with the page number. After trying a lot of things I found out, that if you want to set a footer, you need to create an instance with $pdf = new yourPDFclassName(); (which extends the parent FDF class).

Running the whole thing again I receive the error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 77 bytes) in /..blabla/yourPDFclassName.php on line 16

Does anyone have an idea why this error occurs when I call the child class? I mean it works with the parent class... And btw, 77 bytes are much smaller than the 33554432 bytes ... hmm

class REPORTSPDF extends FPDF { .... }

16: $pdf = new REPORTSPDF();

The line 16 is in the constructor of REPORTSPDF. There are no other lines before line 16. It just crashes when $pdf = new REPORTSPDF() is called.

Without the Footer function I have the same error. The weird thing is that when I change line 16 to

$pdf = new FPDF();

everything works fine (with the exception that I don't have a footer).

A: 

Increase memory limit

There are 3 ways to increase memory limit

  • using config file

    Change memory limit in php.ini

    memory_limit = 32M

  • using PHP

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

  • using htaccess

    php_value memory_limit 32M

Methods in different server

Shared Hosting

php_value memory_limit 32M

Dedicated or VPS Optimized

ssh -lroot domain.com

locate php.ini

vi /usr/local/php/etc/php.ini

edit to 

memory_limit=32M;

save file

httpd restart

/sbin/service httpd restart
JapanPro
But it doesn't seem to be necessary since it works with $pdf = new FPDF()....
mkn
primarily issue with memory
JapanPro
wouldn't it be better to eliminate the problem than to work around it? generating a pdf shouldn't use !32MB! ram
oezi
@oezi that right the more is better, i consider if its shared server then 16m is even good.
JapanPro
A: 

Change your memory_limit.

try,

ini_set('memory_limit','128M');
Yogesh
as said to japanpro: wouldn't it be better to eliminate the problem than to work around it? generating a pdf shouldn't use !32MB! ram
oezi
+2  A: 

The error message means that, while attempting to allocate an additional 77 bytes, the memory limit of 33554432 bytes was exceeded.

There are only two ways around this: either optimize the code in your subclass so you don't need as much memory, or increase your memory limit in php.ini (or using equivalent methods for manipulating with the PHP configuration).

Michael Madsen
+1  A: 

sounds like you have an infinite loop in you code. try to do a simple hello-world-test ans see what happens and check all loop in your code.

oezi
it does have a loop in the constructor... thanks for your help
mkn
A: 

I've not used it myself, but the FPDF2File extension to FPDF is an attempt to build the PDF page by page to disk rather than purely in memory

Mark Baker