DOMPDF extremely slow on rendering

13,306 views
Skip to first unread message

Michael

unread,
Nov 29, 2010, 7:09:25 AM11/29/10
to dompdf
Hi everyone,

I have only really just started using dompdf, so not entirely au fait
with it. However, it seems that it's taking a very long time to render
the PDF, I've found that it's at the point where it runs the reflow()
function, as everywhere else I've placed a die() to determine where
it's slowing down.

This however has only started happening after I re-styled the PDF, and
the only main difference is the increase in styles, and the fact that
it's in a table (before it was just divs).

I know this is not much to go on but I'm really getting confused here,
and I do not understand why on earth it's practically slowing down the
whole site.

If anyone needs me to post any code let me know, as I'm not quite sure
what I should post in order to help solve this problem.

Thanks in advance for any help
MIchael

Fabien Ménager

unread,
Nov 30, 2010, 7:34:04 AM11/30/10
to dompdf
Hello, what version of dompdf do you use? The 0.6 beta, or even better
the latest revisions from the trunk have lots of improvements. I
suggest you to try it.
The reflow method is the starting point of the render, so this is why
it takes so much time.
The render of tables is far more complicated than divs, that's why it
is slower now. What is the size of your document ? how many pages does
the final PDF doc have ?

Michael

unread,
Nov 30, 2010, 8:13:53 AM11/30/10
to dompdf
Thanks for your reply.

I am using the version I downloaded here which CLAIMS to be 0.6.0 but
in the code reads as 0.5.1 which confuses me. Even the SVN version is
0.5.1 so I'm not sure where else to get it?

As for the size, it's dependent, as there could be many PDFs tied
together (it uses a foreach loop to go through profiles on a website)
but with just a singular profile PDF, it's pretty much just text and
one small profile image. Although, as you mention, it is re-done in
tables so it may be the problem.

If you can let me know where to get the actual 0.6 release of dompdf I
would be grateful as I have a feeling I may be downloading the wrong
files.

Regards
Michael

BrianS

unread,
Nov 30, 2010, 1:18:36 PM11/30/10
to dompdf
The version in the svn trunk is the latest. References to it being
0.5.1 should have been removed (though there's still a bit of cleaning
up we have to do, such as the changes cataloged in
dompdf_config.inc.php).

The repository version has a lot of modifications related to speed.
I'd definitely try that one if you are able. It sounds like you're
comfortable using svn, but you can also download the latest code (a
"nightly") from http://eclecticgeek.com/dompdf/

Is the document still rendering and just slower or does it not even
render at this point? If you can supply a sample of the before and
after HTML+CSS that would really help us determine if there's a bug
that needs to be addressed.

Michael

unread,
Dec 1, 2010, 4:13:05 AM12/1/10
to dompdf
Hi, thanks for that. I downloaded the nightly build but still getting
the same issue.

Here is the code (it loops through profiles that are generated via the
database through a class called profile):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<style type="text/css">
body{
margin: 0;
padding: 0;
font-family: Helvetica;
font-size: 60%;
color: #333;
}
p{
line-height: 150%;
margin-top: 3px;
font-size: 55%;
}
h1{
font-size: 200%;
margin: 0;
padding: 0;
letter-spacing: -1px;
line-height: 110%;
}
h2{
font-family: "Times New Roman", Times, serif;
font-variant: small-caps;
font-weight: normal;
margin: 5px 0 60px 0;
border-bottom: 1px solid #666;
padding: 0 0 20px 2px;
font-size: 75%;
letter-spacing: -0.25px;
}
h3{
text-transform: uppercase;
letter-spacing: -0.5px;
font-size: 100%;
padding: 0 0 5px 0;
border-bottom: 1px solid #999;
}
h4{
margin: 0 0 20px 0;
padding: 0;
font-size: 200%;
}
small{
font-variant: small-caps;
font-size: 60%;
display: block;
font-weight: bold;
margin-bottom: 4px;
}
a{
color: #06C;
}
img a{
border: none;
float: left;
}
img{
border: none;
}
</style>
</head>
<body>
<?

foreach($_SESSION['profilebasket'] as $type => $array) {

foreach($array as $id => $name) {
$profile = new profile();
$profile->setId($id);
// Get the name of the person
$profile_rs = mysql_query("SELECT * FROM profiles WHERE profile_id
= '".intval($id)."'");
if(mysql_num_rows($profile_rs) == 1) {
// For each profile add a new page
$row = mysql_fetch_assoc($profile_rs);

?>

<table border="0" width="100%" cellpadding="50" style="margin-top:
50px;">
<tr>

<td width="60%"><h1><?= $profile->getFullName(); ?>&nbsp;<span
class="qualifications"><?= $profile->getHonours(); ?></span></h1>
<h2><? if ( $profile->isMediator() ) { ?>IS A QUALIFIED
MEDIATOR <? } ?></h2>
<p>
<?= $profile->getProfileText(); ?>
</p></td>
<td width="3%" style="border-right:1px dotted #000000;"></td>
<td width="25%" style="padding-left:20px;">
<img src="img/pdf-logo.jpg" width="1200%" />
<br />
<? if(file_exists("profiles/" . $row['profile_id'] . ".jpg"))
{ ?>
<img width="1200%" src="profiles/<?= $row['profile_id']; ?>.jpg"
class="profileImg" alt="Image of <?= $name; ?>" />
<? } else { ?>
<img width="1200%" src="profiles/no-profile.png"
class="profileImg" alt="No profile image" />
<? } ?>


<? if ( $profile->isMediator() ) { ?>

<small>total score</small>
<h4><?= $profile->getTotalScore(); ?></h4>

<small>league table position</small>
<?= $profile->getPosition($profile->getTotalScore()); ?>

<br /><br />

<small>total mediations<br />undertaken</small>
<?= $profile->getTotalCases(); ?>

<br /><br />

<small>member level</small>
<?= $profile->getMemberLevel(); ?>

<? } ?>
<br /><br />


<small><?= $profile->getFirstName(); ?> is a<br />member of</
small>
<ul>
<?= $profile->getGroups(); ?>
</ul>

<small>phone</small>
0845 083 3000<br /><br />

</td>
</tr>
</table>
<?
}
}
}
?>
</body>
</html>

<?
$output = ob_get_contents();
ob_end_clean();

$dompdf = new DOMPDF();
$dompdf->load_html($output);
$dompdf->render();

When it calls the render() function and gets to the frame reflow
that's where is stalls. I did print out the results and flush the
cache and it looks like it's trying to render each segment of each
table cell bit by bit, and just taking forever. And this is just from
one PDF profile - imagine if I had 5 or 10!

Hope that the code I have posted here helps shed some light?

Michael

On Nov 30, 6:18 pm, BrianS <eclecticg...@gmail.com> wrote:
> The version in the svn trunk is the latest. References to it being
> 0.5.1 should have been removed (though there's still a bit of cleaning
> up we have to do, such as the changes cataloged in
> dompdf_config.inc.php).
>
> The repository version has a lot of modifications related to speed.
> I'd definitely try that one if you are able. It sounds like you're
> comfortable using svn, but you can also download the latest code (a
> "nightly") fromhttp://eclecticgeek.com/dompdf/

BrianS

unread,
Dec 1, 2010, 1:23:55 PM12/1/10
to dompdf
I wonder if this could be causing your problem?

<img src="img/pdf-logo.jpg" width="1200%" />

That can be very wide/tall, but I guess it depends on your DPI and
image size. If the resulting image is too big, though, it will cause
you to experience an infinite loop during the document reflow phase.

The easy way to test this out is to remove the images.

Amburi Roy

unread,
Dec 2, 2010, 1:12:03 AM12/2/10
to dom...@googlegroups.com
Hello Michael,
 
I think, if you are using % in width, then that could not be more that 100%. I guess it would be fine if width will be 1200px.
<img src="img/pdf-logo.jpg" width="1200%" />
I guess this is the cause of slow rendering. 
 
Regards,
Amburi Roy


> wrote:
--
You received this message because you are subscribed to the Google Groups "dompdf" group.
To post to this group, send email to
dom...@googlegroups.com.
To unsubscribe from this group, send email to
dompdf+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/dompdf?hl=en.


Michael

unread,
Dec 2, 2010, 4:22:32 AM12/2/10
to dompdf
Thanks for your advice,

I tried removing the images plus all the percentages that I'd used so
now it's a very basic table with just text but it's still stalling,
and flooding the server. The actual reason why I put 1200% is because
the DPI was so low on the image it was coming out really tiny.

I attempted putting it back to floated divs (the nightly build of
domPDF allows floats I found out) but the formatting is just all over
the place - there's obviously a bunch of CSS methods that don't work
properly (specifically the text-align one).

Argh! This is really annoying and I can't think of a suitable solution
- are there any settings I can change do you think that may speed up
the rendering?

Michael

On Dec 2, 6:12 am, Amburi Roy <amburi....@gmail.com> wrote:
> Hello Michael,
>
> I think, if you are using % in width, then that could not be more that 100%.
> I guess it would be fine if width will be 1200px.
> <img src="img/pdf-logo.jpg" width="1200%" />
> I guess this is the cause of slow rendering.
>
>  Regards,
> *Amburi Roy*
> ...
>
> read more »

Michael

unread,
Dec 2, 2010, 5:46:03 AM12/2/10
to dompdf
Thanks for your advice,

I tried removing the images plus all the percentages that I'd used so
now it's a very basic table with just text but it's still stalling,
and flooding the server. The actual reason why I put 1200% is because
the DPI was so low on the image it was coming out really tiny.

I attempted putting it back to floated divs (the nightly build of
domPDF allows floats I found out) but the formatting is just all over
the place - there's obviously a bunch of CSS methods that don't work
properly (specifically the text-align one).

Argh! This is really annoying and I can't think of a suitable solution
- are there any settings I can change do you think that may speed up
the rendering?

Michael

On Dec 2, 6:12 am, Amburi Roy <amburi....@gmail.com> wrote:
> Hello Michael,
>
> I think, if you are using % in width, then that could not be more that 100%.
> I guess it would be fine if width will be 1200px.
> <img src="img/pdf-logo.jpg" width="1200%" />
> I guess this is the cause of slow rendering.
>
>  Regards,
> *Amburi Roy*
> ...
>
> read more »

BrianS

unread,
Dec 2, 2010, 3:12:45 PM12/2/10
to dompdf
So your document renders ok if you switch back to DIVs for your
containers? The bug I mentioned can caused by elements other than
images. I believe any block-level element can experience the problem.
It's mostly experienced with table-based layouts, though. Fabien has a
temporary catch for the problem, but we still have a bit of work to
do.

Also, I believe the focus of float support has been on images, so I'm
not sure you'll get what you expect with other elements.
> ...
>
> read more »

Michael

unread,
Dec 3, 2010, 5:59:21 AM12/3/10
to dompdf
Brian

Yes, I've noticed that I get my text all over the place on my right
column; but the images are fine. I think I should avoid tables but
it's a pain when the alignment of the text doesn't work properly. I'm
guessing I'll have to re-think my layout.

Is there a way of left aligning text better?

Michael
> ...
>
> read more »

Matt Pealing

unread,
Dec 3, 2010, 6:19:36 AM12/3/10
to dom...@googlegroups.com
Hi,
I submitted a message on your support group but it was different to this one I'm afraid! I think this was intended for someone else.

Regards,
Matt.

BrianS

unread,
Dec 3, 2010, 1:57:13 PM12/3/10
to dompdf
I think tables are probably your best option, but there are obviously
some issues that we need to work out on our end. If you can link to a
sample document that actually shows what you're trying to render I may
be able to provide a bit more advice.
> ...
>
> read more »

Michael

unread,
Dec 7, 2010, 4:36:39 AM12/7/10
to dompdf
Unfortunately I cannot show you any example documents due to
confidentiality rules in my company but suffice to say, the layout
without tables looks like it's completely ignoring my style rules. Is
there a list of incompatible style rules somewhere? I would have
thought basic ones like text-align and position would work?
> ...
>
> read more »

BrianS

unread,
Dec 10, 2010, 2:35:13 PM12/10/10
to dompdf
text-align should work fine ... all the styles supported by DOMPDF
0.5.1 are supported. See http://code.google.com/p/dompdf/wiki/CSSCompatibility

We do not have the 0.6.0 compatibility table ready, but if you are
wondering about any specific declaration let us know.
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages