Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dompdf error "No block-level parent found. Not good."

Tags:

php

dompdf

require_once("function/dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
foreach($modules as $module){
   $output = "Hello " .$module['name'];
   $dompdf->load_html($output);
   $dompdf->render();
   $output_pdf = $dompdf->output();
   file_put_contents($dir . $name_modulo . ".pdf", $output_pdf);

}

Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'No block-level parent found. Not good.'

like image 360
Eliana Avatar asked May 30 '16 09:05

Eliana


3 Answers

Late to this thread, but based on the post at https://github.com/dompdf/dompdf/issues/902, I was able to fix this issue by removing spaces between <html><head>, </head><body>, and </body></html>

So, instead of having properly formated html code like this:

<html>
<head>
...
</head>
<body>
...
</body>
</html>

I deleted all the new lines or spaces between the tags, now it looks like this :

<html><head>
...
</head><body>
...
</body></html>

And everything is hunky-dory again

like image 67
Kinglish Avatar answered Oct 16 '22 02:10

Kinglish


dompdf folder > dompdf_config.custom.inc.php file > try to uncomment the line

define("DOMPDF_ENABLE_HTML5PARSER", true);

Also replace unsupported html5 tags & attributes with supported one, clear html errors for better result

like image 19
Nimya V Avatar answered Oct 16 '22 01:10

Nimya V


Just define

$dompdf->set_option('enable_html5_parser', TRUE);

I think it will fix the issue.

Or can edit the dompdf/dompdf_config.inc.php file go to line no 322 change

def("DOMPDF_ENABLE_HTML5PARSER", false);

to

def("DOMPDF_ENABLE_HTML5PARSER", true);
like image 17
Prasant Kumar Avatar answered Oct 16 '22 01:10

Prasant Kumar