error: dompdf.cls.php (331): eval () 'd code on line 2

178 views
Skip to first unread message

editorweb

unread,
Jan 16, 2010, 3:08:13 PM1/16/10
to dompdf
Hello. DOMPDF is very good program. I put it to work on my website.
Perfectly recognized the php and html code and generates the pdf file
but in the pdf document you receive the following error:

Warning: mysql_fetch_object (): supplied argument is not a valid MySQL
result resource in
/ home / xxx / html / xxx / DOMPDF / include / dompdf.cls.php (331):
eval () 'd code on line 2

might help to know the origin of the error.

thanks

codigo

<?php $blog=1; include ("blog.header.php"); ?>
<?php
require_once("/home/sonoro/html/noticias/dompdf/
dompdf_config.inc.php");

$html =

'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-transitional.dtd">'.
'<html xmlns="http://www.w3.org/1999/xhtml">'.
'<head>'.
'<title>aaaaa</title>'.
'<meta http-equiv="imagetoolbar" content="no" />'.
'<meta name="MSSmartTagsPreventParsing" content="TRUE" />'.
'<meta name="Description" content="WEBTITLE content" />'.
'<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />'.
'<meta name="robots" content="all" />'.
'<link href="b2-servicio/estiloi.css" rel="stylesheet" type="text/
css" />'.
'</head>'.

'<body >'.

'<table width="95%" border="0" align="center" cellpadding="0"
cellspacing="0">'.
'<tr>'.
'<!-- CABECERA -->'.
'<td><div align="center"><a href="index.php"><img src="b2-graficos/
banoticias.jpg" width="500" height="101" border="0" /></a></div></
td>'.
'</tr>'.
'<tr>'.
'<td> <br /><br /><br />'.
'<!-- CUERPO -->'.
'<!-- // b2 loop start -->'.
'<?php while($row = mysql_fetch_object($result)) { start_b2(); ?></
p>'.
'<p class="titsecc"> '.
'<?php permalink_anchor(); ?>'.
'</p>'.
'<p align="right"> <span class="pret_port"> <?php the_time("l j M
Y"); ?></p>'.
'<p class="tit_art">'.
'<h3> <?php the_title(); ?></h3>'.
'</p>'.
'<p><span class="firma"><i>x '.
'<?php if (!$row->post_autman)'.
'{ the_author(); } else { the_autman(); } ?></i>'.
'</span> <br /><br /><br />'.
'</span> <span class="pret_port">'.
'<?php the_pretit(); ?>'.
'<br> </span> </p>'.
'<?php the_content(); ?>'.
'<?php link_pages("<br />Pages: ","<br />","number") ?></p>'.
'<?php } ?></p>'.
'</td> </tr> </table>'.
'<!-- PIE -->'.
'<br><hr />'.
'<div align="center"></i><b> aaaaaaa.</b></i></div></td>'.
'</body>'.
'</html>';

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");

?>

BrianS

unread,
Jan 16, 2010, 11:35:00 PM1/16/10
to dompdf

Do you have DOMPDF_ENABLE_PHP set to true in dompdf_config.inc.php? I
would suspect so, because where you're running into trouble is with
the PHP code that's part of your $html variable. This isn't really the
best way to go about generating your document. While DOMPDF *can* do a
lot of what you need, things work best when you generate your document
outside of the DOMPDF instance. Otherwise you will have to modify the
way you reference some functions and variables.

I would just run the PHP code rather than passing it to DOMPDF. when
going through your loops, just concatenate the values to $html. So
instead of this:

$html =
'<html><body>'.
'<?php while($row = mysql_fetch_object($result)) {?>'.


'<h3> <?php the_title(); ?></h3>'.

'<?php } ?>
'</body></html>'
;

I would do something like this:

$html = '<html><body>';
while($row = mysql_fetch_object($result)) {
$html .= '<h3>' . the_title() . '</h3>';
}
$html .= '</body></html>';

That code is, obviously, just a sample based on what you provided.

Also, an unrelated observation. You're using a lot more string
concatenation than you need. I assume this is to make the code a
little easier to read, but it can end up costing you in resource usage
and performance. Rather than concatenate all those separate lines of
text you can continue the string on the next line, like this:

$html =
'<html>
<head>
<title>a simple document</title>
</head>
<body>
<p>very simple</p>
</body>
</html>
';

-b

Paul Waring

unread,
Jan 17, 2010, 6:25:07 AM1/17/10
to dom...@googlegroups.com
BrianS wrote:
> Also, an unrelated observation. You're using a lot more string
> concatenation than you need. I assume this is to make the code a
> little easier to read, but it can end up costing you in resource usage
> and performance. Rather than concatenate all those separate lines of
> text you can continue the string on the next line, like this:

Better still, use a template library, such as Smarty[1], which will
parse a template and produce the HTML for you. This also gives you the
advantage of the templates being cached, which should help performance.

Paul

[1] http://www.smarty.net/

--
Paul Waring
http://www.pwaring.com

Reply all
Reply to author
Forward
0 new messages