Search code examples
laravellaravel-3

Laravel 3 Snappy bundle Class Snappy not found


I'm struggling to get the Snappy bundle to work.

It keeps telling me that the Snappy Class is not found.

I've installed the bundle and added it to the bundles.php file for auto loading.

But still nothing.

All help is appreciated :) Thanks


Solution

  • I found the solution,

    I had everything installed correctly but the issue was I should be using namespaces. On the bundle page it says the usage is something like this.

    Bundle::start('snappy');
    $snappy = Snappy::make('/usr/bin/wkhtmltopdf');
    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename="file.pdf"');
    echo $snappy->getOutput('http://laravel.com');
    exit;
    

    The correct way to do this is to use the namespace like so

    Bundle::start('snappy');
    
    // the following two lines is added
    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://laravel.com');
    exit;