Snappy Image Wrapper for Laravel

Snappy[1] is a PHP library allowing thumbnails, snapshots, and PDF generation from a URL or … Read more Snappy Image Wrapper for Laravel

Snappy[1] is a PHP library allowing thumbnails, snapshots, and PDF generation from a URL or HTML page. Barry vd. Heuvel[2] is the author of a Laravel Snappy[3] (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[4] (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[5]; be sure to check it out for more examples of available methods and test assertions.

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

Filed in:
News[8]

References

  1. ^ Snappy (github.com)
  2. ^ Barry vd. Heuvel (github.com)
  3. ^ Laravel Snappy (github.com)
  4. ^ wkhtmltopdf (wkhtmltopdf.org)
  5. ^ readme (github.com)
  6. ^ barryvdh/laravel-snappy (github.com)
  7. ^ KnpLabs/snappy (github.com)
  8. ^ News (laravel-news.com)


Source: Laravel News


Categories: DevelopmentTags:

Tags:


Leave a Reply

Your email address will not be published. Required fields are marked *