0
votes

I use in controler:

 $html = $this->renderView('RaportBundle:pdf:magazinesbarcode.html.twig', array(
            'magazines'  => $magazines
        ));

        return new Response(
            $this->get('knp_snappy.pdf')->getOutputFromHtml($html,
                array('images'=> true,'enable-external-links' => true)
            ),
            200,
            array(
                'images' =>true,
                'Content-Type'          => 'application/pdf',
                'Content-Disposition'   => 'attachment; filename="file.pdf"'
            )
        );

Normal documentation example. HTML generate well, with my absolute img path

<img src="{{ asset('uploads/barcode/2.jpg', absolute=true) }}" /> 

But in pdf image didn't displayed. If i saved generated html and use wkhtmltopdf on this file from console image saves well in pdf. So problem is in Snappy budle. Windows 8.1 x64. Whats wrong?

1

1 Answers

0
votes

You should use absolute local path to an image:

<img src="{{ rootDir ~ '/web' ~ asset('uploads/barcode/2.jpg') }}">

where rootDir is passed to the template:

$html = $this->renderView('RaportBundle:pdf:magazinesbarcode.html.twig', array(
            'magazines'  => $magazines,
            'rootDir' => $this->get('kernel')->getRootDir().'/..'
        ));