Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 603
Md. Sahadat Hossain Avatar asked Jan 08 '18 08:01

Md. Sahadat Hossain


2 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

like image 83
Geraldo Novais Avatar answered Oct 14 '22 01:10

Geraldo Novais


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;
}
like image 1
Victor Priceputu Avatar answered Oct 14 '22 01:10

Victor Priceputu