Maxime
Maxime

Reputation: 2234

Add Symfony bundle to Silex Framework

I have a Silex project and I'm trying to generate a pdf file from a twig view with the KnpSnappyBundle . I have the following code in my controller :

$this->app['knp_snappy.pdf'] = new KnpSnappyBundle($this->app, $this->client);

And then I have something like that :

if ($request->get('print') == 'print') {
    $html = $body;

    return new Response(
        $app['knp_snappy.pdf']->getOutputFromHtml($html),
        200,
        array(
            'Content-Type'          => 'application/pdf',
            'Content-Disposition'   => 'attachment; filename="file.pdf"'
        )
    );
}

I have the following error : Fatal error: Call to undefined method Knp\Bundle\SnappyBundle\KnpSnappyBundle::getOutputFromHtml()

Can you guys help me to fix that problem or to find another way to get pdf file from html with Silex (I tried domtopdf, it works, but it's ugly and it seems to not support svg images)...

Maybe I found another way to do that but I guess i'll have the same problem... PdfBundle

Upvotes: 1

Views: 1498

Answers (1)

Jakub Matczak
Jakub Matczak

Reputation: 15656

KnpSnappyBundle is just a wrapper of SNappy library, therefore it doesn't make sense to try to inject it into Silex application. It's not worth it.

Simply use Snappy. Register Pdf class as a service an than it will work as you expect it to do.

Also you can check this SilexServiceProvider for Snappy if you're not sure how to put it into your DI container.

Upvotes: 1

Related Questions