【问题标题】:Laravel HTML to PDF conversion (DOMPDF)Laravel HTML 到 PDF 的转换 (DOMPDF)
【发布时间】:2015-12-19 04:49:00
【问题描述】:

用于 Laravel 5 的 DOMPDF Wrapper,它是用于 laravel 5 的 html 到 pdf 转换器。

我尝试将 laravel 默认的认证注册页面转换为 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文件夹吗?
  • @MustafaEhsan,存储目录中没有文件夹
  • @MustafaEhsan,谢谢,这是文件夹问题。我已经在存储中创建了字体文件夹,现在正在生成 PDF。
  • 欢迎,我也发布了我的解决方案作为答案。

标签: php laravel laravel-5 dompdf


【解决方案1】:

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 {} \;
【解决方案2】:

将主题的“fonts”目录从“project-directory/public/themes/your-theme/path-to-fonts-directory”位置复制到该位置 '项目目录/存储/字体目录' 当我被绞死很长时间时,这对我有用。

【讨论】:

  • 我已经复制了您在此处提到的字体文件夹。但仍然遇到同样的错误
  • 你给'fonts-directory'起什么名字?它应该是“字体”
猜你喜欢
  • 1970-01-01
  • 2015-07-08
  • 2015-06-09
  • 1970-01-01
  • 2011-06-17
  • 2020-09-19
  • 1970-01-01
  • 1970-01-01
  • 2012-12-07
相关资源
最近更新 更多