【发布时间】:2021-05-03 10:14:31
【问题描述】:
使用 laravel 的 barryvdh/laravel-dompdf 包在 Laravel 中生成 PDF 时出现以下错误。
图片未找到或类型未知
HTML
<html>
<head>
<style>
table
{
border-color: #000;
color: #000;
border-collapse: collapse;
font-family: sans-serif;
}
</style>
</head>
<body>
<table style="width: 100%; margin-top: 10px;" cellpadding="3" border="1">
<tr>
<td style="text-align: right; font-weight: bold; font-size: 14px; padding-left: 5px;">User Image</td>
<td colspan="4" style="height: 50px;">
<img src="/val/test/storage/images/profile_1611820816863.jpg" height="70">
</td>
</tr>
</table>
</body>
</html>
等级
$complete_html = '<above HTML>';
$dompdf = new Dompdf();
$dompdf->loadHtml($complete_html);
$page_size = 'A4';
$dompdf->setPaper($page_size, 'portrait');
$dompdf->render();
$file_name = 'test_dom';
$dompdf->stream($file_name.'.pdf', array("Attachment" => 1));
我已查看有关此主题的其他帖子,并在 dompdf 配置文件中将“RemoteEnable”设置为 true,然后重新启动服务器,但仍然遇到此问题。
编辑 我已更改图像路径,它是共享文件夹路径,而不是项目或本地路径。 此外,文件和文件夹路径都具有完全的读写权限(777)
【问题讨论】:
-
你试过img src的完整网址吗?
-
@FirdausNasir 我的图像文件位于存储文件夹或不在公共文件夹中的某个共享网络文件夹中,因此我无法使用完整 URL,我只能使用绝对路径。
-
以下答案是否解决了问题