laravel-dompdf: DOMPDF_Exception "No block-level parent found. Not good."
Hi, im working on a project and I’m using your dompdf to create and render PDFs. Rendering PDFs is a success on my localhost but what’s odd is it throws DOMPDF_Exception "No block-level parent found. Not good."
error on live server. Any idea how to fix this?
Im using loadView()
function…
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 27
The solution from @frin seems to be doing the trick! Better than debugging your html template. I used
$dompdf->set_option('enable_html5_parser', TRUE);
to enable the option.Removing the entire HEAD section fixed my issue. Use inline styles, like an EDM.
Thanks for that link @vaites I used another better solution on that page which is:
You have to set option enable_html5_parser to true, then it works again with libxml2 2.9.5 or newer. This also fixed the issue of “Cannot redeclare …” function, if you had any PHP functions inside the template/HTML.
Guys, the problem in CSS. I removed the CSS and it worked. DOMPDF use CSS 2.1.
Change:
To:
in /vendor/barryvdh/laravel-dompdf/src/PDF.php
Notice:
$html = preg_replace('/>\s+</', '><', $html);
in the second one.NEVER change the code in your vendor folder. A pull request may be better than that. The next time you try to update the code, it will override the change and you are back to square 1. Plus how will you deploy? Normally the vendor folder is not supposed to be version controlled, so your change will not go beyond your local code.
My fix came with adding the following styling in the template:
html, body {display: block;}
Had the same issue, for me it was caused by the
html
tag not being detected as a block-level parent. Had to add the following CSS to fix it:html, body { display: block; }
I was able to fix this error by remove this CSS definition in de body section
Switched everything back on, even the fonts (who are responsible for massive delay when included) and it worked, so the display:table is the culprit here.