Want to take your software engineering career to the next level? Join the mailing list for career tips & advice Click here


Laravel Snappy PDF

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682 (1 ratings)
Rated 4.0 out of 5
Subscribe to updates I use laravel-snappy

Statistics on laravel-snappy

Number of watchers on Github 923
Number of open issues 142
Average time to close an issue 17 days
Main language PHP
Average time to merge a PR 8 days
Open pull requests 9+
Closed pull requests 10+
Last commit over 2 years ago
Repo Created over 6 years ago
Repo Last Updated over 2 years ago
Size 59 KB
Organization / Authorbarryvdh
Latest Releasev0.4.1
Page Updated
Do you use laravel-snappy? Leave a review!
View open issues (142)
View laravel-snappy activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
Evaluating laravel-snappy for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Snappy PDF/Image Wrapper for Laravel 5 and Lumen 5.1

For Laravel 4.x, check version 0.1

This package is a ServiceProvider for Snappy: https://github.com/KnpLabs/snappy.

Wkhtmltopdf Installation

Choose one of the following options to install wkhtmltopdf/wkhtmltoimage.

  1. Download wkhtmltopdf from here;
  2. Or install as a composer dependency. See wkhtmltopdf binary as composer dependencies for more information.

Attention! Please note that some dependencies (libXrender for example) may not be present on your system and may require manual installation.

Testing the wkhtmltopdf installation

After installing you should be able to run wkhtmltopdf from the command line / shell.

If you went for the second option the binaries will be at /vendor/h4cc/wkhtmltoimage-amd64/bin and /vendor/h4cc/wkhtmltopdf-amd64/bin.

Attention vagrant users!

Move the binaries to a path that is not in a synced folder, for example:

cp vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64 /usr/local/bin/
cp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 /usr/local/bin/

and make it executable:

chmod +x /usr/local/bin/wkhtmltoimage-amd64 
chmod +x /usr/local/bin/wkhtmltopdf-amd64

This will prevent the error 126.

Package Installation

Require this package in your composer.json and update composer.

composer require barryvdh/laravel-snappy


After updating composer, add the ServiceProvider to the providers array in config/app.php


Optionally you can use the Facade for shorter code. Add this to your facades:

'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,

Finally you can publish the config file:

php artisan vendor:publish --provider="Barryvdh\Snappy\ServiceProvider"

Snappy config file

The main change to this config file (config/snappy.php) will be the path to the binaries.

For example, when loaded with composer, the line should look like:

'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),

If you followed the vagrant steps, the line should look like:

'binary'  => '/usr/local/bin/wkhtmltopdf-amd64',

For windows users you'll have to add double quotes to the bin path for wkhtmltopdf:

'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"'


In bootstrap/app.php add:

class_alias('Barryvdh\Snappy\Facades\SnappyPdf', 'PDF');

Optionally, add the facades like so:

class_alias(Barryvdh\Snappy\Facades\SnappyPdf::class, 'PDF');
class_alias(Barryvdh\Snappy\Facades\SnappyImage::class, 'SnappyImage');

To customise the configuration file, copy the file /vendor/barryvdh/laravel-snappy/config/snappy.php to the /config folder.


You can create a new Snappy PDF/Image instance and load a HTML string, file or view name. You can save it to a file, or inline (show in browser) or download.

Using the App container:

$snappy = App::make('snappy.pdf');
//To file
$html = '<h1>Bill</h1><p>You owe me money, dude.</p>';
$snappy->generateFromHtml($html, '/tmp/bill-123.pdf');
$snappy->generate('http://www.github.com', '/tmp/github.pdf');
//Or output:
return new Response(
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'attachment; filename="file.pdf"'

Using the wrapper:

$pdf = App::make('snappy.pdf.wrapper');
return $pdf->inline();

Or use the facade:

$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');

You can chain the methods:

return PDF::loadFile('http://www.github.com')->inline('github.pdf');

You can change the orientation and paper size

PDF::loadHTML($html)->setPaper('a4')->setOrientation('landscape')->setOption('margin-bottom', 0)->save('myfile.pdf')

If you need the output as a string, you can get the rendered PDF with the output() function, so you can save/output it yourself.

See the wkhtmltopdf manual for more information/settings.


This Snappy Wrapper for Laravel is open-sourced software licensed under the MIT license

laravel-snappy open issues Ask a question     (View All Issues)
  • over 3 years Rasterize PDF and Signature Field
  • over 3 years The exit status code '126' says something went wrong
  • over 3 years Class Barryvdh\Snappy\ServiceProvider not found
  • over 3 years PDF header and footer
  • over 3 years RuntimeException
  • over 3 years Problem display Asset
  • almost 4 years margin-top cuts off header
  • almost 4 years Greek characters problem in footer and header
  • almost 4 years The process has been signaled with signal "11".
  • almost 4 years Symfony\Component\Process\Exception\ProcessTimedOutException after 60 seconds
  • almost 4 years The exit status code '2'
  • almost 4 years The exit status code '134' says something went wrong stderr: "QXcbConnection: Could not connect to display Abosrted"
  • almost 4 years Exit with code 1 due to network error: HostNotFoundError
  • almost 4 years Strange behavior - duplicate inserts
  • about 4 years escapeshellarg() has been disabled for security reasons
  • about 4 years Unable to call the Snappy from within the Controller
  • about 4 years Method setOption() removes HTML symbol on Linux
  • about 4 years Error Google Chart
  • about 4 years Print color instead of grey pdf.
  • about 4 years thead and tbody contents overlap from second page onwards
  • over 4 years new changes for Lumen support
  • over 4 years Problem With Encoding
  • over 4 years Won't load assets from public folder on shared hosting
  • over 4 years Windows server 2012, IIS, exit status code '1'
  • over 4 years Laravel 5, Windows 7, PDF
  • over 4 years Laravel-Snappy Installation on Godaddy share hosting
  • over 4 years Failing to load resources from http://localhost:8888
  • over 4 years Send laravel session?
  • over 4 years Send generated file as multipart.
  • over 4 years Call to undefined method Knp\Snappy\Pdf::loadView()
laravel-snappy open pull requests (View All Pulls)
  • Use fully-qualified class names in return docblocks for download and stream methods of PdfWrapper
  • highlights
  • Facade class referenced by using the ::class function
  • Enable overwriting of files
  • Adding language hints to code blocks.
  • add support for env variables
  • added addView method
  • Added info for using laravel-snappy in Homestead
  • Added setTempFolder fluent method to PdfWrapper
laravel-snappy questions on Stackoverflow (View All Questions)
  • laravel-Snappy PDF DIVs incorrectly sized using height:11in
  • Laravel / Snappy: can not generate PDF or create folder
  • Could not install laravel-snappy in laravel 4
laravel-snappy list of languages used
Other projects in PHP