有一种方法可以将渲染的视图下载为jpeg

问题描述 投票:0回答:3

当前报告正以html文件的形式生成。

$view = view('spark::settings.report.html.content', compact('data'))->render();
header("Content-type: text/html");
header("Content-Disposition: attachment; filename=".$file_name.".html");
return $view;

但是我的客户现在希望将其作为jpeg文件。我尝试过这种方式

$view = view('spark::settings.report.html.content', compact('data'))->render();
header("Content-type: image/jpeg");
header("Content-Disposition: attachment; filename=".$file_name.".jpeg");
return $view;

找不到任何解决方案。

php laravel laravel-5.8
3个回答
1
投票

您需要获取包含所需数据的HTML,并使用库将其另存为PNG,JPEG ...等

在这种情况下,如果您需要图像,可以使用:

https://github.com/spatie/browsershot


0
投票

您可以使用https://github.com/barryvdh/laravel-snappy

用于生成具有刀片视图的图像或pdf。

详细文档在此链接中。


0
投票

有很多软件包,但是最好的是[html2cinvas] [۱]

© www.soinside.com 2019 - 2024. All rights reserved.