【问题标题】:Adding Image PHPWord in Laravel在 Laravel 中添加图像 PHPWord
【发布时间】:2021-11-01 15:49:55
【问题描述】:

所以我想在 Laravel 的 PHPWord 中为我的文档添加一个标题图像。 所以这是我的代码

public function generateDocx()
{
    $phpWord = new \PhpOffice\PhpWord\PhpWord();
    $section = $phpWord->addSection();

    $headerLogo = 'http://127.0.0.1:8000/img/logoAnevBulanan.png';
    $section->addImage($headerLogo);

    // Bunch of line to download the docx
}

我得到了超过 60 秒的最大执行时间,当我尝试来自 documentation 的其他方法时,我仍然遇到同样的错误。我尝试使用来自 laravel 的 asset() 助手,但仍然无法正常工作

【问题讨论】:

    标签: laravel phpword


    【解决方案1】:

    尝试使用本地路径而不是 URL 获取图像

    $source = file_get_contents('/path/to/my/images/earth.jpg');
    $textrun->addImage($source);
    

    参考文档:https://phpword.readthedocs.io/en/latest/elements.html#images

    【讨论】:

      猜你喜欢
      • 2015-05-11
      • 1970-01-01
      • 2020-05-13
      • 2014-07-19
      • 2021-01-24
      • 1970-01-01
      • 2014-07-23
      • 2015-04-20
      • 2019-03-20
      相关资源
      最近更新 更多