未创建KnpSnappyBundle文件

问题描述 投票:0回答:1

我在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算法的人,说实话我真的不明白它是如何工作的,我所知道的只是我已经在另一个项目中使用它并且它工作得很好..

symfony pdf symfony4 knp-snappy
1个回答
0
投票

它要求你没有的图书馆......

libQt5Svg.so.5:无法打开共享对象文件:没有这样的文件或目录

如果您使用的是Ubuntu,请安装它。

sudo apt-get install libqt5svg5
© www.soinside.com 2019 - 2024. All rights reserved.