Laravel HTML转PDF(DOMPDF)转换

7

DOMPDF Laravel 5包装器,它是一个用于Laravel 5的html转pdf转换器。

我尝试将laravel默认的auth注册页面转换为PDF,路径为http://www.careertag.dev/auth/register。用于此目的的代码如下所示。但我遇到了字体问题。请问您能否帮我解决这个问题?

routes.php

Route::post('/screenshot', function(){
    $pdf  =  App::make('dompdf.wrapper');
    //$pdf->loadHTML('<h1>Test</h1>');
    $view =  View::make('auth.register')->render();
    $pdf->loadHTML($view);
    $pdf->stream();
    //return $pdf->stream('invoice');
    return $pdf->download('profile.pdf');
});

错误

ErrorException in font_metrics.cls.php line 343: file_put_contents(C:\xampp\htdocs\careertag\storage\fonts/13350985545a9988387f8a573f409063.ttf): failed to open stream: No such file or directory

你的 storage 目录下有一个 fonts 文件夹吗? - Mustafa Ehsan Alokozay
@MustafaEhsan,存储目录中没有文件夹。 - Sarath TS
1
@MustafaEhsan,谢谢,这是一个文件夹问题。我已经在存储中创建了字体文件夹,现在PDF正在生成。 - Sarath TS
欢迎,我也已经将我的解决方案发布为答案。 - Mustafa Ehsan Alokozay
2个回答

9
storage目录下创建一个名为fonts的文件夹,并确保storage可被Web服务器写入,运行以下命令即可。这对我有用。
sudo chmod -R 777 storage

上述(777)可能会有危险性,因此为了以安全的方式实现它,请尝试以下命令。
sudo find storage -type d -exec chmod 755 {} \; 
sudo find storage -type f -exec chmod 644 {} \;

777很危险。这样可能更好: sudo find storage -type d -exec chmod 755 {} \; sudo find storage -type f -exec chmod 644 {} \; - balping

1

将主题中的“字体”目录从位置“project-directory/public/themes/your-theme/path-to-fonts-directory”复制到位置“project-directory/storage/fonts-directory”。当我卡了很长时间时,这对我有用。


我已经按照您在此处提到的方式复制了字体文件夹,但仍然出现相同的错误。 - user2717410
你给'fonts-directory'取什么名字?应该是'fonts'。 - Md Aman Ullah

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接