Rendering multiple HTML segments

551 views
Skip to first unread message

John Colvin

unread,
Jan 28, 2011, 1:15:21 PM1/28/11
to dompdf
I've had success creating small PDFs with DOMPDF, but now I'm trying
to generate PDFs that have hundreds of pages. This can be done, but it
uses a lot of memory. I've been toying around in the code trying to
find some way to get around this memory issue.

I'm wondering if it's possible to add html to a DOMPDF object, render
that html then add more add HTML and render it. My thought is that the
memory usage is so high because a style object is associated with
every frame, so a large PDF will have tons of objects. Then all of
those objects are processed into coordinates during the render. It
would be much more efficient to just hold the coordinate information
and clear out all of the objects and move on to the next section of
HTML.

Any thoughts about how this could be accomplished or any other ideas
about how to keep the memory under control?

Thanks.

BrianS

unread,
Jan 29, 2011, 10:30:57 AM1/29/11
to dompdf
Currently I can't think of any way that this could be done with dompdf
alone without some modification of the code internals. I have done
something similar in the past, though, using dompdf in conjunction
with pdftk. In that case, every page of the document used a fairly
precise layout. Because of this I could render each page separately. I
would save the resulting PDF to a file. After all pages had been
rendered I used pdftk to join the individual files into a single file.
The dompdf object had to be destroyed each time to ensure that the
memory was released, but it resulted in a lighter memory load and
speedier rendering with larger documents in my case.

The upcoming release will include some performance-related
improvements, but we're hoping to make this a focus of the project
within the next few releases.


On Jan 28, 1:15 pm, John Colvin <john.col...@eschoolconsultants.com>
wrote:

John Colvin

unread,
Jan 31, 2011, 12:56:37 PM1/31/11
to dompdf
I've made a few additions to the dompdf class that allows for this
functionality. It's only about 10 SLOC. With these changes I've
generated a 300 page PDF with less than 50 MB of memory usage.

It might not be exactly what you're looking for in the next release,
but it might help. I'd be happy to share this with you. How should I
go about submitting these changes to you?

BrianS

unread,
Jan 31, 2011, 6:33:33 PM1/31/11
to dompdf
Head over to the issue tracker and add an enhancement request and
attach your code changes. If you can also supply a diff that would be
great.
http://code.google.com/p/dompdf/issues/list

On Jan 31, 12:56 pm, John Colvin <john.col...@eschoolconsultants.com>

Hermann Herz

unread,
May 21, 2014, 4:11:17 AM5/21/14
to dom...@googlegroups.com
I also want to render a pdf with about 150 pages and end in a timeout :(

So BriansS or John, did you provide these "10 SLOC" in order I can render these 150 pdf pages with dompdf?

Thanks

BrianS

unread,
May 21, 2014, 3:21:21 PM5/21/14
to dom...@googlegroups.com
This issue is relevant: https://github.com/dompdf/dompdf/issues/231
You can get the attached files from the Google Code site: https://code.google.com/p/dompdf/issues/detail?id=225

The way Colvin worked around the issue was to chunk the HTML and modify dompdf to be able to process multiple HTML segments.
Reply all
Reply to author
Forward
0 new messages