Welcome Guest, Not a member yet? Register   Sign In
trying to genereate pdfs w/ dompdf: memory size exhausted
#1

[eluser]lolmann[/eluser]
I'm creating a larger number of PDFs with dompdf and write them to a folder. In order to do this, I loop through a set of database rows and for each row I call
Code:
pdf_create($html, $filename, FALSE)
as described in this wiki article.

When I try to create more than 10 PDFs or so the process errors
Code:
[09-Oct-2010 19:35:52] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 1245184 bytes) in /Applications/MAMP/htdocs/mydirectory/system/plugins/dompdf/lib/class.pdf.php(2219) : eval()'d code on line 5914

Basically it says that the PDF creation is using more than 32 MB Ram.

Each of the PDFs is only 4 KB.

I temporarily got the whole think working by putting
Code:
ini_set("memory_limit","120M");
in the beginning of the plugin function. It increases the memory limit to 120 MB. This works for creating 10 PDFs. But as soon as I want more (30 PDFs or so) the same thing happens and I have to increase the memory limit even more.

So far I'm testing the whole thing on my local machine and can put up the memory limit. But I figure that the ressources on my webspace are more limited and 120 MB seems too much.

What can I do to make the PDF creation less of a memory sucker?

(I originally posted this over here but am hoping to get some more attention by opening a thread on its own. Sorry for the repost. Please answer in this thread.)
#2

[eluser]Bas Vermeulen[/eluser]
Sorry this is not really on topic, but why are you using dompdf (I see more people over here doing that)? I thought it isn't actively developed anymore? TCPDF is so I started using that. I'm just wondering....
#3

[eluser]lolmann[/eluser]
[quote author="Bas Vermeulen" date="1286725261"]Sorry this is not really on topic, but why are you using dompdf (I see more people over here doing that)? I thought it isn't actively developed anymore? TCPDF is so I started using that. I'm just wondering....[/quote]

Afaik dompdf is still in active development. Here's the link to the new project page.

I chose dompdf because it allows me to create a pdf straight from a codeigniter view file (HTML, CSS). See the wiki article I linked above. Can TCPDF do this? Is there an easy way to integrate it into my codeigniter project?
#4

[eluser]Bas Vermeulen[/eluser]
Lol, my bad.. I somehow thought it was dead. You sure it hasn't been dead for awhile?

I never tried creating a pdf from a view with TCPDF, I just do it all in my controller and found the integration to be pretty easy:

Code:
// Load TCPDF
require_once( APPPATH . 'third_party/tcpdf/config/lang/eng.php');
require_once( APPPATH . 'third_party/tcpdf/tcpdf.php');
// Create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

Then you can load w/e you want into this instance (headers, footers, pages, titles, etc) followed by:
Code:
$pdf->Output($dir.''.$file, 'F');


The link to that wiki article isn't working Smile
#5

[eluser]lolmann[/eluser]
Does anybody know how I can solve this problem and continue to use dompdf?
[quote author="Bas Vermeulen" date="1286758950"]The link to that wiki article isn't working Smile[/quote]
I updated the link above and here is it once more: Codeigniter and dompdf
#6

[eluser]iloveci[/eluser]
I've encountered this problem many times too. For the project I was working on the fix was correcting the pdf template used to generate the pdf's. Dompdf does not like url-links for css or image files, it instead wants the file path to those assets.

So instead of using:
Code:
echo link_tag('css/style.css');
Try using
Code:
<link  href="../../css/style.css" rel="stylesheet" type="text/css" />

Good luck & Let me know if it helped.




Theme © iAndrew 2016 - Forum software by © MyBB