Snappy Image Wrapper for Laravel

Snappy Image Wrapper for Laravel

Snappy is a PHP library allowing thumbnails, snapshots, and PDF generation from a URL or HTML page. Barry vd. Heuvel is the author of a Laravel Snappy (which has been around since Laravel 5), making it even easier to integrate with Laravel:

// Generate a PDF From a view
$pdf = PDF::loadView('pdf.invoice', $data);
$pdf->download('invoice.pdf');

// Generate a PDF from a URL
PDF::loadFile('https://www.github.com')
     ->inline('github.pdf');

// Change the orientation and paper size
PDF::loadHtml($html)
     ->setPaper('a4')
     ->setOrientation('landscape')
     ->setOption('margin-bottom', 0)
     ->save('myfile.pdf');

Along with some nifty convenience methods, Snappy for Laravel has testing features to help you assert things that Snappy generates:

PDF::fake();

// Perform order shipping...

PDF::assertViewIs('view-pdf-order-shipping');
PDF::assertSee('Name');

Snappy requires the wkhtmltopdf (available on Windows, Mac, and Linux), which is a command-line tool to render HTML into PDF and various image formats. Installation instructions are available in the readme so you can ensure wkhtmltopdf is installed and the path configured properly.

Learn More

The code examples are directly from the project’s readme; be sure to check it out for more examples of available methods and test assertions.

To get started, barryvdh/laravel-snappy has full installation instructions and source code. Also, be sure to check out KnpLabs/snappy for further details on using Snappy.

Filed in: News

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Software Developer
Remote (US & Canada)
Alley
😎 Laravel Developer
Remote
Jogg, Inc
Junior, Mid, and Senior Software Engineers. Laravel / Vue. Saint Petersburg, FL
Saint Petersburg, FL and Remote
ShineOn
Senior PHP Developer (Laravel)
Remote
The Interaction Design Foundation
Fullstack Laravel Engineer (Munich/Remote) 💻
Munich, Germany or Remote
AirLST GmbH