I have installed Print and TCPDF on a client's site for testing and when I attempt to generate a PDF through the Print module, I get the following error. It's trying to allot the same amount of memory regardless of what node I try to print to PDF.
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1921722737 bytes) in C:\...\www\sites\default\modules\print\tcpdf\tcpdf.php on line 4282
I installed TCPDF by itself and tested out the samples packaged with it and they worked fine; it seems to only cause an error when I'm using TCPDF through Print. The server is Apache running on windows. On my local test machine, running unix and apache, it works fine.
I also get this error on the next page I visit after trying to print to a PDF
warning: fread() [function.fread]: Length parameter must be greater than 0 in C:\...\www\sites\default\modules\print\tcpdf\tcpdf.php on line 4282.
Any suggestions? I'm out of ideas.
Comments
Comment #1
jcnventuraNo.
I have no idea why tcpdf would try to allocate 2Gb of memory... TCPDF is quite strange with images and doesn't care when the width and height are set via styles... Try to remove all images (including from the header and the footer) and see if its still causing problems..
Comment #2
seancorrales commentedI created a blog post with no images and it still had the issue. I took a look at the code a bit closer and saw that the error at 4282 is an error with the PNG parser. I disabled the header and all others worked fine.
TCPDF's comments said that it uses a PNG parser if it doesn't have access to GD libraries AND the directory defined in K_PATH_CACHE. Since Print configures this manually, does anyone know what it sets the K_PATH_CACHE to?
Comment #3
jcnventuraK_PATH_CACHE is set to the 'cache' directory inside the directory where the tcpdf.php file is found (as seen in admin/settings/print/pdf).
Try a newer version of TCPDF to see if it manages to create the PDF with your header logo.. If not, then it seems that disabling your logo may currently the only solution to the problem.
João
Comment #4
okaalto commentedI have the same problem with latest TCPDF version (4.5.026). TCPDF's internal "PNG parser" does not work very well with remote files, i.e. when the file source is remote URL, not a local path. The parser tries to read image data and parse it in the same loop, which works ok with local files, but not always with remote files. This leads to not reading correctly all image data chunks from PNG-file, which leads to wrong chunk sizes, which ends up with trying to allocate huge amout of memory during fread() causing the error message.
It seems that TCPDF prefers its internal parser over GD in all cases instead of when it has determined to do some image resizing. I tried a hackish solution of forcing TCPDF to use GD by commenting out some code, but it seems that the images are resized too small in that case.
edit: I posted a bug report to TCPDF site but unfortunately it was not accepted. I also found a post at TCPDF support forum about the same problem (using pchart to generate images) but no solution yet. https://sourceforge.net/forum/message.php?msg_id=6469505
edit2: Added more information to the problem description, just in case there's someone interested.