Laravel PDF:找不到块级父级。不好

时间:2018-01-08 08:14:28

标签: php laravel pdf laravel-5.2 dompdf

我的代码工作正常,直到今天。我没有改变任何东西,但突然我的PDF代码无法正常工作。我在barryvdh/laravel-dompdf中使用laravel 5.2这个包。

我删除了本地项目并从实时服务器下载但仍然在我的本地计算机上出现此问题。我的实时项目可以正常使用此代码。

这是我的代码

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

我收到此错误 enter image description here

我也尝试将enable_html5_parser设置为true。在此之后,我又收到了另一个错误 enter image description here

2 个答案:

答案 0 :(得分:7)

找不到块级父级。不好。这是一个解析器错误

你好朋友,

如果删除html,head和body标签之间的空格,可以修复它,如下所示:

有效:

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

失败:

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

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

当我更新我的php时,我有同样的问题,使用相同的laravel版本 从5.6到7.0版本。

当我尝试生成pdf文件时,抛出了消息:

找不到块级父级。不好。

此解决方案可在此github页面中找到

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

我希望我有用

答案 1 :(得分:0)

有同样的问题,对我来说,这是由于未将html标记检测为块级父级引起的。 必须添加以下CSS对其进行修复:

html, body {
    display: block;
}