Ale*_*pov 3 html php render dompdf laravel
我正在尝试使用 laravel 和 dompdf lib 生成 pdf 文件。这是我的控制器代码:
public function create(Request $request) {
$pdf = new Dompdf();
$html = Storage::disk('local')->get('public/pdf/template.html');
$pdf->loadHtml($html, 'UTF-8');
$pdf->setPaper('A4', 'portrait');
$pdf->render();
$filename = "Hi!";
return $pdf->stream($filename, ["Attachment" => false]);
}
Run Code Online (Sandbox Code Playgroud)
我template.html得到了一些 html,在某个地方我得到了这样的图像:
<img src="img/logo.png" alt="BTS">
但 dompdf 无法写入此图像:Image not found or type unknown。我的文件系统是:
.pdf
...img
......here is images
...template.html
...*some_fonts_files*
但与此同时,字体加载得很好。我应该怎么做才能在 template.html 中渲染图像?
我相信对于 dompdf 您需要传递一个可正确访问的 url 而不是相对路径。
尝试
<img src="{{ asset('img/logo.png')}}" alt="BTS">
或者,如果资产不起作用,请尝试
<img src="{{ public_path('img/logo.png')}}" alt="BTS">
另请注意,asset 使用公共目录作为 base_url 来计算“asset”。
| 归档时间: |
|
| 查看次数: |
17602 次 |
| 最近记录: |