Issues with generate PDF file from big HTML file

2,030 views
Skip to first unread message

anhbn.niit

unread,
May 24, 2011, 6:28:17 AM5/24/11
to dompdf, anh...@freshstudio.biz
Dear Mod, Authors,

Recently, I need to generate a PDF file from a big HTML file (size of
HTML file is about 42MB).
Unfortunately, it's not successful.
Error message: Fatal error: Allowed memory size of 1073741824 bytes
exhausted (tried to allocate 51 bytes) in D:\xampp\htdocs\test
\crate_label\include\frame_tree.cls.php on line 161

I tried to increase the memory size from 128M to 512M,1024M but also
unsuccessful.
So, I need your suggestion or solution for my situation.

I uploaded full source into the following address:
http://www.mediafire.com/?1l45yrb3gdyczd2
I'm looking forward for your reply.
Thank you!
Best regards,

soso

unread,
May 26, 2011, 3:18:16 AM5/26/11
to dompdf
The only way I know of you can get around this issue is to generate
batches of a few pages and merge them at the end in one big pdf.
http://groups.google.com/group/dompdf/browse_thread/thread/27cb6897f74b4c7f

BrianS

unread,
May 26, 2011, 3:06:35 PM5/26/11
to dom...@googlegroups.com
This is the way I would go for a document like this. It's highly structured so you should be able to easily break it up into multiple documents.

I've only taken a cursory look at the code, so correct me if I'm wrong, but is the whole document one big table? If If so then you should at least remove the outermost table. I don't see anything that this table provides that you couldn't get with individual tables for each row. You would definitely see better performance.

John Colvin

unread,
May 26, 2011, 4:45:04 PM5/26/11
to dompdf
I've solved this problem with a bit of hacking at the core code as
described here: http://code.google.com/p/dompdf/issues/detail?id=225

My needs were also highly structured, so I created the HTML broken
into divs with the class "page" and split based on that. I then used a
method that I wrote in an extended class called insert_html. I go into
more depth in the issue linked above.

It cuts the memory usage way down.

anhbn.niit

unread,
May 30, 2011, 5:27:16 AM5/30/11
to dompdf
Can you help me by share full demo code?
I'm look forward for your reply.
Many thanks!

On May 27, 3:45 am, John Colvin <john.col...@eschoolconsultants.com>
wrote:

John Colvin

unread,
Jun 1, 2011, 9:12:16 AM6/1/11
to dompdf
All the code you should need is in the issue that I opened here:
http://groups.google.com/group/dompdf/browse_thread/thread/a39c007e4da5bde

Apply the patch to the dompdf class. Add my extended dompdf class to
your project. Use this block of code:

$doc = new DOMDocument();
$doc->loadHTML($html);

$dompdf = new DOMPDF_ext();

// Get the style section out of the HTML
$styles = $doc->getElementsByTagName('style');
$style = $styles->item(0);

// Get all the divs with class page (separate pages)
$xpath = new DOMXPath($doc);
$pages = $xpath->query('//div[contains(@class, "page")]');

// insert each page individually
foreach($pages as $page) {
$html = $doc->saveXML($style) . $doc->saveXML($page);
$dompdf->insert_html($html);
}

$dompdf->stream($document_name . '.pdf');

Where $html is the full HTML of the PDFs you want to generate. Each
page should be in a div with class page. That's how this code knows to
break up the HTML.
Reply all
Reply to author
Forward
0 new messages