我正在使用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算法的人,老实说我不太了解它是如何工作的,我所知道的就是,我已经在另一个项目中使用了它,而且效果很好。
答案 0 :(得分:0)
它正在请求您没有的图书馆...
libQt5Svg.so.5:无法打开共享库文件:无此文件或 目录
如果您使用的是Ubuntu,请安装它。
sudo apt-get install libqt5svg5