Forum Moderators: coopster

Message Too Old, No Replies

error using dompdf

when converting html tables into pdf

         

Silent Miracle

6:52 am on Jul 18, 2011 (gmt 0)

10+ Year Member



hello ... i tried dompdf to convert a php code to pdf. But when it encounters the tables in php it gives error.

Fatal error: Call to undefined method Inline_Frame_Decorator::normalise() in C:\wamp\www\include\table_frame_decorator.cls.php on line 252
CAn anyone please guide me why i am getting this error.. Here is my code

<?php
include('dompdf_config.inc.php');

global $_dompdf_show_warnings;
global $_dompdf_debug;
global $_DOMPDF_DEBUG_TYPES;

$outfile = 'test.pdf';
$save_file = TRUE; // Save the file or not
$buff = file_get_contents('task.php');
$dompdf = new DOMPDF();
$base_path = $_SERVER['DOCUMENT_ROOT'];

$dompdf->load_html($buff);
if ( isset($base_path) ) {
$dompdf->set_base_path($base_path);
}
$dompdf->render();
file_put_contents($outfile, $dompdf->output( array("compress" => 0) ));

if (!headers_sent() )
$dompdf->stream($outfile);
?>

and here is code for task.php

<?php
error_reporting(E_ALL);
mysql_connect("localhost","root","root");
$db=mysql_select_db("reportinfo");

$str="SELECT report_id FROM report WHERE report_id='1'";
$v=mysql_query($str) or die('Error'.mysql_error());
$s=mysql_fetch_array($v);
mysql_num_rows($v);
$st="SELECT * FROM section WHERE report_id ='".$s[0]."' ORDER BY position";
$res=mysql_query($st) or die('Error'.mysql_error());
echo "<br/>";
mysql_num_rows($res);
$ans="SELECT user_name FROM report WHERE report_id='1'";
$ansr=mysql_query($ans);
$r=mysql_fetch_array($ansr);
echo "<div align=\"center\">";
echo "<B>WELCOME </B>".$r[0]. "<B>&nbsp&nbsp TO YOUR REPORT</B>";
echo "</div>";
echo "<br/>";
$kr=0;
while ($kr<mysql_num_rows($res))
{
$result=mysql_fetch_array($res);

echo "<div align=\"center\">";
echo $result['content'];
echo "</div>";
echo "<br/>";

$kr++;

}
print ("<form Name=\"theform\">");
print ("<input type=\"submit\" name=\"submit\"value=\"Convert to PDF\"onClick=\"submitfunction(1)\"/>");
print ("</form>")

?>
<SCRIPT>
function submitfunction(i)
{
if(i==1)
document.theform.action="sample.php";
document.theform.submit

}
</SCRIPT>

penders

7:59 am on Jul 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've not used dompdf, but (this might sound a silly question) can dompdf cope with plain text (ie. your PHP code)? It is an HTML to PDF converter. If it tries to parse plain text as HTML then it would be reasonable to assume this might cause an error.

But when it encounters the tables in php it gives error.


What tables?

echo "<B>WELCOME </B>".$r[0]. "<B>&nbsp&nbsp TO YOUR REPORT</B>";


Just noticed... unrelated to your immediate problem but these HTML entities are not complete, should be "&nbsp;&nbsp;" (with semi-colons)

Silent Miracle

8:15 am on Jul 18, 2011 (gmt 0)

10+ Year Member



actually these are the html tables saved in the database... the whole html code for the table is saved in the database.. like when the task.php code is executed... and the database values are acuired then the values are in the form of html code like :


<table>
<th> PAtient Information </th>

<tr>
<td>Name;Silent_Miracle </td>
</tr>


</table>
so this whole html table code should get into result['content'] and eventually displayed. IT is displayed but when i try to convert this webpage into pdf i amd getting that error

dompdf easily converts all the html codes into pdf but couldnot process <table> tag

penders

9:19 am on Jul 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Again, this might be my misunderstanding of how dompdf works, but...

$buff = file_get_contents('task.php');


...this line gets the raw contents of "task.php". It does not process the PHP so nothing is being read from your database at this stage. Unless the load_html() method ("
$dompdf->load_html($buff);
") evaluates PHP (which I doubt?) then you are parsing plain text (your raw PHP source code) not HTML through dompdf, which by the sound of it is not what you require. (Although you did state in your OP, "...to convert a php code to pdf" so I did wonder :)