laravel-snappy pdf generation fails with no error

3.9k Views Asked by At

I have installed laravel-snappy following the instructions on https://github.com/barryvdh/laravel-snappy

Following the installation I tested wkhtmltopdf and it works:

vagrant@homestead:/usr/local/bin$ /usr/local/bin/wkhtmltopdf google.com /tmp/google.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

I can confirm the pdf exists:

vagrant@homestead:/tmp$ ls
google.pdf

This is the contents of the snappy.php file:

return array(


    'pdf' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltopdf',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltoimage',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),


);

However when I run this in my Controller, nothing happens. No error message and no file generated:

function pdfreport($id)

{
    $html = '<h1>hi</h1>';

    $pdf = PDF::loadHTML($html)->setPaper('a4')->setOrientation('portrait');

    return $pdf->download('test.pdf');

}

I was expecting the pdf to start downloading. What could be the issue?

1

There are 1 best solutions below

0
On BEST ANSWER

I have made this work by installing snappy without the laravel wrapper. Then simply doing this:

use Knp\Snappy\Pdf;

$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutput('http://www.github.com');

Perhaps there is an issue with the laravel wrapper.