# Snappy [](https://ci.appveyor.com/project/NiR-/snappy) [](https://scrutinizer-ci.com/g/KnpLabs/Gaufrette/?branch=master) Snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. It uses the excellent webkit-based [wkhtmltopdf and wkhtmltoimage](http://wkhtmltopdf.org/) available on OSX, linux, windows. You will have to download wkhtmltopdf `0.12.x` in order to use Snappy. Please, check [FAQ](doc/faq.md) before opening a new issue. Snappy is a tiny wrapper around wkhtmltox, so lots of issues are already answered, resolved or wkhtmltox ones. Following integrations are available: * [`knplabs/knp-snappy-bundle`](https://github.com/KnpLabs/KnpSnappyBundle), for Symfony * [`barryvdh/laravel-snappy`](https://github.com/barryvdh/laravel-snappy), for Laravel * [`mvlabs/mvlabs-snappy`](https://github.com/mvlabs/MvlabsSnappy), for Zend Framework ## Installation using [Composer](http://getcomposer.org/) ```bash composer require knplabs/knp-snappy ``` ## Usage > ⚠️ **Security Warning** > > The `--enable-local-file-access` option in `wkhtmltopdf` can be risky if used with untrusted HTML or JavaScript. > This may expose local files or lead to remote code execution. > > To stay safe: > - Avoid enabling `--enable-local-file-access` unless necessary. > - Always sanitize user input before processing. > - Run `wkhtmltopdf` in a sandbox like **AppArmor** or **SELinux**. > - For untrusted content, consider alternatives like **WeasyPrint**, **Prince**, or **Puppeteer**. > > This risk was responsibly reported by > **Nikita Sveshnikov (Positive Technologies)**. > > 🔗 [Official recommendations](https://wkhtmltopdf.org/status.html#recommendations) ### Initialization ```php setBinary('/usr/local/bin/wkhtmltopdf'); ``` ### Display the pdf in the browser ```php $snappy = new Pdf('/usr/local/bin/wkhtmltopdf'); header('Content-Type: application/pdf'); echo $snappy->getOutput('http://www.github.com'); ``` ### Download the pdf from the browser ```php $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'); ``` ### Merge multiple urls into one pdf ```php $snappy = new Pdf('/usr/local/bin/wkhtmltopdf'); header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="file.pdf"'); echo $snappy->getOutput(array('http://www.github.com','http://www.knplabs.com','http://www.php.net')); ``` ### Generate local pdf file ```php $snappy = new Pdf('/usr/local/bin/wkhtmltopdf'); $snappy->generateFromHtml('