4

I have form.php file that getting data from mysql table. form.php

<?php
 if(mysql_num_rows($sql)==0){
?>
<table>
    <tr>
        <td>1.</td>
        <td>America</td>
    <tr>
</table>
<a href="pdf.php" target="_blank">Export as PDF</a>
<?php
 } else {
?>
<table>
    <tr>
        <td>1.</td>
        <td>India</td>
    <tr>
</table>
<a href="pdf.php" target="_blank">Export as PDF</a>
<?php
 }
?>

And pdf.php

require_once("dompdf/dompdf_config.inc.php");
ob_start();
$html = file_get_contents('form.php');
$dompdf = new DOMPDF();
date_default_timezone_set('Asia/Kolkata');
$tym = date('g:i s');
$filename = 'FAA-8130_3_'.$tym;
$dompdf->load_html($html);
ob_end_flush();
$dompdf->render();
$dompdf->stream($filename. ".pdf", array("Attachment" => 0));

When I try to export it as PDF file, it is giving error...

Fatal error: Call to a member function prepend_child() on a non-object in C:\wamp\www\path\to\dompdf\include\frame_tree.cls.php on line 231

I could not understand why it is happening. I viewed this,this and this, but failed to resolve.

Community
  • 1
  • 1
Raja
  • 772
  • 1
  • 15
  • 38

1 Answers1

1

dompdf before 0.6.1 would support processing PHP prior to rendering to PDF. That was removed for security reasons and so you should now fully process any PHP in your document prior to feeding it to dompdf.

The code in pdf.php is close, but not quite correct. The following should work (I also re-organized for readability).

date_default_timezone_set('Asia/Kolkata');
require_once("dompdf/dompdf_config.inc.php");

$tym = date('g:i s');
$filename = 'FAA-8130_3_'.$tym;

ob_start();
require_once 'form.php';
$html = ob_get_clean();
ob_end_clean();

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($filename. ".pdf", array("Attachment" => 0));
BrianS
  • 13,284
  • 15
  • 62
  • 125