首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Laravel软件包html到pdf

Laravel软件包html到pdf
EN

Stack Overflow用户
提问于 2016-01-16 16:44:49
回答 1查看 5.9K关注 0票数 2

我使用了以下软件包将html转换为pdf:

https://github.com/vsmoraes/pdf-laravel5

但是当我用这个的时候,它根本不是在看。这是我原来的html pdf:

当我转换它时,它看起来是这样的:

我在这里做错什么了吗?

编辑:

代码语言:javascript
运行
复制
public function __construct(Pdf $pdf)
{
    $this->pdf = $pdf;
}
public function download()
{
    $html = view('administration.invoice')->render();
    return $this->pdf->load($html)->download();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-16 17:10:45

这个laravel包似乎正在使用DOMPDF,这是很棒的。

请记住,我看不到您的代码,我将共享为我工作的PHP代码:

代码语言:javascript
运行
复制
// This should be your normal HTML page
$url = 'http://www.website.com/invoice';
$html = file_get_contents($url);

// First. Convert all relative image paths to file system paths.
// Test that the generated path is where your images files are located
$html = str_replace("/images", public_path()."/images", $html);

// Generate PDF file
$dompdf = new DOMPDF();
$dompdf->set_paper("A4", "portrait");
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream('your_invoice_file.pdf');

如果您还想直接呈现一个Laravel视图以PDF格式,请用这一行代码替换前两行代码

代码语言:javascript
运行
复制
// Just render the view normally
$html = View::make('path/view');

如果添加了代码,则可以选择其他选项。

代码语言:javascript
运行
复制
$html = view('administration.invoice')->render();
$html = str_replace("/images", public_path()."/images", $html);
return $this->pdf->load($html)->download();

请记住将“图像”文件夹设置为您拥有的文件夹。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34829446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档