[dompdf] Dynamic HTML Problems

1,005 views
Skip to first unread message

Chris

unread,
May 19, 2010, 11:05:57 AM5/19/10
to dompdf
Hello,

I recently installed DOMpdf as a means of replacing html2pdf on our
server. After we upgraded from PHP 5.1 to 5.3.2, our dynamically-
generated pdf process stopped working. The original process was
calling a script on the server, passing a GET variable, and using that
variable to generate dynamic content in the resulting html.

After the upgrade, a pdf would get created, but would be blank and
give the error "Acrobat could not open 'test.pdf' because it is either
not a supported file type or because the file has been damaged." I
uploaded the file "test.pdf" as an example. I assumed that this meant
that the file was never being written in the first place. I decided to
try DOMpdf in the hopes that it would eliminate this problem. I solved
the initial setup problem that I discussed in an earlier thread on
this forum and was eventually able to output an html string without a
problem. I went to try and include the original dynamic page using
$dompdf->load_html_file() and sure enough, I got the same error as
when I was using html2pdf.

As a test, I took the html table, complete with dynamic content, and
moved it all over to the original file. I turned the table into one
giant html string. I then tried outputting the file again and got the
same error. I then stripped out the vast majority of the html string
and left a few paragraphs in. The pdf was created properly, so this
leads me to think that there is something in the html that DOMpdf
doesn't like. Can anyone see anything glaring that needs to be
omitted? I've been trying to troubleshoot this problem for a solid two
weeks now, so any help would be very much appreciated. Thanks.

<div id="pageContent" style="padding: 0px 0px 0px 0px; background-
image: none;text-align:center; width:100%;">

<center>
<div id="acknowledgment">
<table border=0 cellpadding="0" cellspacing="0" width="704"
style="margin-top:50px;margin-bottom:50px;">
<tr>
<td style="background-image:url(/images/ack-top.gif);background-
repeat:no-repeat;height:33px;"></td>
</tr>
<tr>
<td class="size13 black_txt" style="background-image:url(/images/
ack-middle.gif);background-repeat:repeat-y;padding:25px;">
<?=$logo?>
<center><span class="size18 bold">Lorem Ipsum</span></center>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Etiam tempor tempus quam viverra hendrerit. Fusce vitae placerat sem.
Sed nibh arcu, fringilla et placerat in, adipiscing et nulla. Quisque
ut augue ligula. Morbi hendrerit porta lectus, sit amet adipiscing
arcu bibendum vel. Mauris et metus a lacus posuere tristique. Praesent
dignissim mattis <?=$company['name']?> purus nec sagittis. In eget
purus ut ligula euismod sodales. Phasellus ac nibh orci. Proin augue
nisl, egestas vel eleifend et, molestie ut tellus. In pulvinar nibh
sit amet justo volutpat tincidunt ullamcorper ut risus. Aliquam justo
orci, porta vel malesuada eget, vehicula ut elit. Etiam blandit, lacus
sit amet elementum hendrerit, ligula lectus hendrerit eros, <?=
$company['name']?> vel hendrerit enim ipsum sit amet arcu. Nam eu odio
arcu. Sed accumsan, enim eget fringilla commodo, lorem nulla egestas
nibh, sed porta turpis enim ac mauris. Nullam volutpat condimentum
ultricies. Proin malesuada mattis augue quis facilisis. Sed sed <?=
$company['name']?> purus purus, sit amet scelerisque erat. Sed eget
sem diam.</p>
<center>
<form method="post" action="#" id="ack" name="ack">
<br/><br/>
<table border=0 cellpadding="5" cellspacing="0" width="75%">
<tr>
<td align="right" valign="top" class="size13 bold"
style="padding-top:6px;">Full Name:</td>
<td align="left" class="size13 bold" style="padding-left:
25px;"><input type="text" name="fullname" value="<?=
$ackinfo['fullname']?>" class="jsrequired ackinput" readonly/></td>
</tr>
<tr>
<td align="right" valign="top" class="size13 bold"
style="padding-top:6px;">Electronic Signature:</td>
<td align="left" class="size13 bold" style="padding-left:
25px;"><input type="text" name="esig" value="<?=$esig?>"
class="jsrequired ackinput" readonly/></td>
</tr>
<tr>
<td colspan="2" style="padding:10px;"><?=date("m/d/Y h:i a")?
></td>
</tr>
</table>
</form>
</center>

</td>
</tr>
<tr>
<td style="background-image:url(/images/ack-
bottom.gif);background-repeat:no-repeat;height:33px;"></td>
</tr>
</table>
</div>
</center>
</div>

--
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.

BrianS

unread,
May 19, 2010, 1:22:55 PM5/19/10
to dompdf
Your PDF contains a lot of non-PDF content that looks like part of
your site template. Do you have display_errors set to on and content
buffering enabled?

The non-PDF content indicates that you're experiencing script errors
due to deprecated function usage. Some of these functions are in your
script (mysql_db_query and eregi). Some are due to DOMPDF. Which
version of DOMPDF are you using? I believe all the 5.3 compatibility
problems have been addressed (though I can't remember if that was for
the 0.6.0 beta 1 release or is part of the development code base).

I recommend that you either set display_errors to off or turn off
buffering for your DOMPDF script.

Chris

unread,
May 19, 2010, 2:00:59 PM5/19/10
to dompdf
Thanks for the suggestion, Brian. I am using version 0.5.3. I turned
off php error display and the html string I used worked, albeit the
formatting is off considering I didn't use the whole page. I wanted to
try using the remote file again and seem and am getting a blank page
since I turned off errors. Is this the correct way to try and send a
get variable to a remote file using DOMPDF?

$dompdf = new DOMPDF();
$dompdf->load_html_file($_SERVER['DOCUMENT_ROOT']."/pdf_ack.php?
_w=" . $getvar);
$dompdf->render();
$dompdf->stream($getvar . ".pdf");

BrianS

unread,
May 19, 2010, 8:29:35 PM5/19/10
to dompdf
$_SERVER['DOCUMENT_ROOT'] provides the physical path to the root
folder of the web site. This means you are essentially doing something
like:

$dompdf->load_html_file("/srv/www/htdocs/pdf_ack.php?_w=" .
$getvar);

This won't work because the PHP will be loaded like a plain-text file.
I think what you really want to do is something along the lines of:

$dompdf->load_html_file($_SERVER['SERVER_HOST']."/pdf_ack.php?_w=" .
$getvar);

When you do this, your web server will process your PHP file as normal
and pass the results back to DOMPDF>

Chris

unread,
May 20, 2010, 8:05:05 AM5/20/10
to dompdf
I tried that at one point. When I do this, it gives the following
error and warning:

Warning: file_get_contents(/pdfack.php?_w=59832) [function.file-get-
contents]: failed to open stream: No such file or directory in /var/
www/vhosts-development/www.loremipsum.com/html/ext/dompdf/include/
dompdf.cls.php on line 261

Fatal error: Uncaught exception 'DOMPDF_Exception' with message
'Requested HTML document contains no data.' in /var/www/vhosts-
development/www.loremipsum.com/html/ext/dompdf/include/
frame_tree.cls.php:135 Stack trace: #0 /var/www/vhosts-development/
www.loremipsum.com/html/ext/dompdf/include/dompdf.cls.php(293):
Frame_Tree->build_tree() #1 /var/www/vhosts-development/
www.loremipsum.com/html/ext/dompdf/include/dompdf.cls.php(377): DOMPDF-
>_process_html() #2 /var/www/vhosts-development/www.loremipsum.com/
html/dompdftest.php(58): DOMPDF->render() #3 {main} thrown in /var/www/
vhosts-development/www.loremipsum.com/html/ext/dompdf/include/
frame_tree.cls.php on line 135
> ...
>
> read more »

Chris

unread,
May 20, 2010, 8:59:55 AM5/20/10
to dompdf
I checked to verify that I was pointing to the right path and the file
has the proper permissions as well.

On May 20, 8:05 am, Chris <wfnt...@gmail.com> wrote:
> I tried that at one point. When I do this, it gives the following
> error and warning:
>
> Warning: file_get_contents(/pdfack.php?_w=59832) [function.file-get-
> contents]: failed to open stream: No such file or directory in /var/
> www/vhosts-development/www.loremipsum.com/html/ext/dompdf/include/
> dompdf.cls.php on line 261
>
> Fatal error: Uncaught exception 'DOMPDF_Exception' with message
> 'Requested HTML document contains no data.' in /var/www/vhosts-
> development/www.loremipsum.com/html/ext/dompdf/include/
> frame_tree.cls.php:135 Stack trace: #0 /var/www/vhosts-development/www.loremipsum.com/html/ext/dompdf/include/dompdf.cls.php(293):
> Frame_Tree->build_tree() #1 /var/www/vhosts-development/www.loremipsum.com/html/ext/dompdf/include/dompdf.cls.php(377):DOMPDF->_process_html() #2 /var/www/vhosts-development/www.loremipsum.com/

Chris

unread,
May 20, 2010, 10:23:38 AM5/20/10
to dompdf
If I change load_html_file() just just load_html(), it creates a pdf
but it still has the same original error as before. I have uploaded
the latest pdf "test-17.pdf". I opened it in wordpad and it looks like
a normal html file, so I'm not sure where it is getting corrupted.

BrianS

unread,
May 30, 2010, 8:31:12 PM5/30/10
to dompdf
It looks like $_SERVER['DOCUMENT_ROOT'] is empty. Have you tried
supplying a full URL (e.g. http://example.com/pdfack.php?_w=59832)?
The path it's trying to parse won't work because it's treating it like
a regular file, not web-based, dynamically-generated PHP ... and that
path doesn't parse to a valid file. Also, have you tried using the
output method instead of stream?


On May 20, 8:05 am, Chris <wfnt...@gmail.com> wrote:
> I tried that at one point. When I do this, it gives the following
> error and warning:
>
> Warning: file_get_contents(/pdfack.php?_w=59832) [function.file-get-
> contents]: failed to open stream: No such file or directory in /var/
> www/vhosts-development/www.loremipsum.com/html/ext/dompdf/include/
> dompdf.cls.php on line 261
>
> Fatal error: Uncaught exception 'DOMPDF_Exception' with message
> 'Requested HTML document contains no data.' in /var/www/vhosts-
> development/www.loremipsum.com/html/ext/dompdf/include/
> frame_tree.cls.php:135 Stack trace: #0 /var/www/vhosts-development/www.loremipsum.com/html/ext/dompdf/include/dompdf.cls.php(293):
> Frame_Tree->build_tree() #1 /var/www/vhosts-development/www.loremipsum.com/html/ext/dompdf/include/dompdf.cls.php(377):DOMPDF->_process_html() #2 /var/www/vhosts-development/www.loremipsum.com/
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages