LargeTuna
LargeTuna

Reputation: 2824

KnpSnappyBundle Save File To Server

I am missing something in the KnpSnappy Bundle docs. :( How do I save my pdf to the server using Symfony and KnpSnappy. I don't want my pdf to download to the browser. I want it to save to the server. Please help! Thanks so much.

 Server Path: $pdfFolder = $_SERVER['DOCUMENT_ROOT'].'/symfonydev/app/Resources/account_assets/'.$account_id.'/pdf/'; 

 return new Response(
        $this->get('knp_snappy.pdf')->getOutputFromHtml($content),
        200,
        array(
            'Content-Type'          => 'application/pdf',
            'Content-Disposition'   => 'attachment; filename="'.$pdfFolder.''.strtotime('now').'.pdf"'
        )
    );

Upvotes: 4

Views: 4603

Answers (2)

Michael Sivolobov
Michael Sivolobov

Reputation: 13240

As you can see from documentation you need to use another function:

$this->get('knp_snappy.pdf')->generateFromHtml($content, $pdfFolder . time() . '.pdf';

As you can see I replaced your strtotime('now') by time(). It will be faster.

Upvotes: 5

ethan
ethan

Reputation: 111

This line generates the PDF...

$this->get('knp_snappy.pdf')->getOutputFromHtml($content)

So you could probably just use file_put_contents to write the result of getOutputFromHtml($content) to the file system.

Upvotes: 4

Related Questions