Symfony2 - 使用 Tcpdf 捆绑包生成 PDF 文件时出错


Symfony2 - error while generating PDF file with Tcpdf Bundle

在我的用于生成PDF的树枝模板中,我有:

<img src="{{ asset('bundles/myBundle/images/no_avatar.jpg') }}">

当我尝试生成 PDF 时,出现错误:

[Symfony'Component'Debug'Exception'ContextErrorException]
Warning: getimagesize(/bundles/wrbmcisintranetsite/images/no_avatar.jpg): f
ailed to open stream: No such file or directory

Exception trace:
() at /var/www/site/vendor/tecnickcom/tcpdf/include/tcpdf_images.php:171
Symfony'Component'Debug'ErrorHandler->handleError() at n/a:n/a
getimagesize() at /var/www/site/vendor/tecnickcom/tcpdf/include/tcpdf_images.php:171

当我更改存储此图像的路径时,例如:

<img src="{{ asset('var/storage/images/no_avatar.jpg') }}">

并在不使用的情况下复制该文件assets:install web它的工作原理和图像在输出 PDF 文件中可见。我想将文件放入MyBundle/Resources/public/images以将其与assets:install一起安装

您需要为所有资产(包括CSS)传递绝对URL。

在您的情况下,可以尝试absolute_url 作为示例:

<img src="{{ absolute_url(asset('images/logo.png')) }}" alt="Symfony!" />

此处文档中的更多信息