Dompdf error “No block-level parent found. Not good.”

≡放荡痞女 提交于 2019-12-07 07:17:57

问题


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


回答1:


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

define("DOMPDF_ENABLE_HTML5PARSER", true);

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




回答2:


Just uncomment define("DOMPDF_ENABLE_HTML5PARSER", true); this line from dompdf_config.custom.inc.php this file.

You can find this file for codeigniter in vendor/dompdf/dompdf this directory.




回答3:


go to configuration file dompdf_config.custom.inc.php and uncomment define("DOMPDF_ENABLE_HTML5PARSER", true); and check, basically it requires html5 parser enabled in your configuration file.




回答4:


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);



回答5:


I don't know why the answer regarding ("DOMPDF_ENABLE_HTML5PARSER", true) was voted down either. Because I spent over 30 hours trying to figure out why this was happening in my website, until I came across this solution. So I enabled the "DOMPDF_ENABLE_HTML5PARSER" by setting it to "TRUE" as noted above. And immediately the error regarding "No block-level parent found" was resolved and my scripts worked. Maybe the 2nd answer was voted down because it duplicated a previous answer (but cut a guy a break, why don't you? Maybe he didn't see it..). Or maybe the "downvoter" has an attitude problem.




回答6:


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 honky dory again



来源:https://stackoverflow.com/questions/37521775/dompdf-error-no-block-level-parent-found-not-good

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!