symfony - 未创建 KnpSnappyBundle 文件
问题描述
我在 Symfony4 上,我正在使用 knpSnappyBundle。我遇到了一个我无法解决的奇怪错误:
[snappy] An error happened while generating "/tmp/knp_snappy5c86716975a458.88561675.pdf". ["command" => "/var/www/html/gestImmo/bin/wkhtml2pdf --lowquality --user-style-sheet './build/app.css' '/tmp/knp_snappy5c867169759ed9.86228916.html' '/tmp/knp_snappy5c86716975a458.88561675.pdf'","status" => 127,"stdout" => "/var/www/html/gestImmo/bin/wkhtmltopdf: error while loading shared libraries: libQt5Svg.so.5: cannot open shared object file: No such file or directory\n","stderr" => ""]
In AbstractGenerator.php line 350:
The file '/tmp/knp_snappy5c86716975a458.88561675.pdf' was not created
(command: /var/ww
w/html/gestImmo/bin/wkhtml2pdf --lowquality --user-style-sheet
'./build/app.css' '/tmp/
knp_snappy5c867169759ed9.86228916.html' '/tmp/knp_snappy5c86716975a458.88561675.pdf').
也许你想要我的代码所以这是我的服务`
namespace App\Service;
use App\Entity\RentRelease;
use App\Repository\PropertyRepository;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
use Knp\Snappy\Pdf;
class PdfGenerator
{
/**
* @var PropertyRepository
*/
private $propertyRepository;
/**
* @var Pdf
*/
private $knpSnappyPdf;
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var \Twig_Environment
*/
private $twig;
public function __construct(
PropertyRepository $propertyRepository,
Pdf $knpSnappyPdf,
EntityManagerInterface $em,
\Twig_Environment $twig
) {
$this->propertyRepository = $propertyRepository;
$this->knpSnappyPdf = $knpSnappyPdf;
$this->em = $em;
$this->twig = $twig;
}
public function generateRentReleasePdf()
{
$rentRelease = $this->em->getRepository(RentRelease::class)->findAll();
foreach ($rentRelease as $release) {
$date = $release->getDate()->format('m-Y');
$currentDate = new \DateTime();
$currentDate = $currentDate->format('m-Y');
if ($date === $currentDate) {
$propertyName = $release->getPropertyName();
$lesseeName = $release->getLesseeName();
$html = $this->twig->render('rent_release/pdf.html.twig', [
'rent_release' => $release,
]);
return new PdfResponse(
$this->knpSnappyPdf->getOutputFromHtml($html, [
'user-style-sheet' => ['./build/app.css',],
]),
'/public/generated/' . $propertyName . '_' . $lesseeName . '_' . date("m-Y") . '.pdf'
);
}
}
}
}
这是我的 bin/ 目录中的 wkhtml2pdf
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROD_ENV=true
if [ $PROD_ENV == true ]
then
xvfb-run $DIR/wkhtmltopdf $@
else
wkhtmltopdf $@
fi
我不是创建 wkhtml2pdf 算法的人,老实说,我并不真正了解它是如何工作的,我所知道的只是我已经在另一个项目中使用它并且它工作正常..
解决方案
它正在请求一个您没有的库...
libQt5Svg.so.5:无法打开共享对象文件:没有这样的文件或目录
如果您使用的是 Ubuntu,请安装它。
sudo apt-get install libqt5svg5
推荐阅读
- ruby-on-rails - Hyperloop 可以使用最新的 Async/Await 吗?
- c# - 一段时间后,随机数生成器给出相同的数字
- java - 在 Vaadin Flow 中处理登录和授权的最佳方法?
- python - 在输入时调整图像大小
- visual-studio - 如何在网格元素 Xamarin 表单中将项目排成一行
- php - Mysql/PHP - 在 php 中显示 group_concat 值
- java - 用Java实现归并排序
- asp.net-mvc - ASP.NET MVC:在视图中呈现字符串
- javascript - vanilla js 'keyup' 可以工作,但不能在表单元素上'submit' 事件监听器
- c# - 如何将二维数组设置为单元测试的参数