Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KnpSnappyBundle Save File To Server

Tags:

php

pdf

symfony

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"'
        )
    );
like image 854
LargeTuna Avatar asked Jan 12 '23 05:01

LargeTuna


1 Answers

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.

like image 105
Michael Sivolobov Avatar answered Jan 16 '23 23:01

Michael Sivolobov