Home » Php » php – Laravel PDF: No block-level parent found. Not good

php – Laravel PDF: No block-level parent found. Not good

Posted by: admin July 12, 2020 Leave a comment

Questions:

My code was just working fine until today. I did not change anything but suddenly my pdf code not working. I am using barryvdh/laravel-dompdf this package in laravel 5.2.

I deleted my local project and download from the live server but still, this problem occurs on my local computer. My live project works fine with this code.

Here is my code

$pdf = App::make('dompdf.wrapper');
$pdf->loadView('back_end.pdf_template.make_invoice', ['order_info' =>$order_info, 'order_details' => $order_details]);
return $pdf->stream('inv-' . $order_info->invoice_id . '.pdf');

I am getting this error
enter image description here

I also try enable_html5_parser set to true. And after this, I am getting another error
enter image description here

How to&Answers:

No block-level parent found. Not good. This is a parser error

hello friend,

It can be fixed if you delete spaces between the html, head and body tags, as shown below:

It works:

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

It fails:

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

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

I had the same problem, with the same laravel version, when I updated my php
from 5.6 to 7.0 version.

When I tried to generate the pdf file the message was thrown:

No block-level parent found. Not good.

This solution was found in this github page

https://github.com/dompdf/dompdf/issues/1582#issuecomment-359448550

I hope I have been useful

Answer:

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