KnpLabs/snappy is tracked by TopGit as an image tool, with 4.5k stars on GitHub, written primarily in PHP. PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
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
available on OSX, linux, windows.
You will have to download wkhtmltopdf 0.12.x in order to use Snappy.
Please, check FAQ 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, for Symfony
barryvdh/laravel-snappy, for Laravel
mvlabs/mvlabs-snappy, for Zend Framework
Installation using Composer
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.
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
Initialization
<?php
require __DIR__ . '/vendor/autoload.php';
use Knp\Snappy\Pdf;
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
// or you can do it in two steps
$snappy = new Pdf();
$snappy->setBinary('/usr/local/bin/wkhtmltopdf');
Display the pdf in the browser
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
header('Content-Type: application/pdf');
echo $snappy->getOutput('http://www.github.com');
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
$snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', '/tmp/bill-123.pdf');
Pass options to snappy
// Type wkhtmltopdf -H to see the list of options
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
$snappy->setOption('disable-javascript', true);
$snappy->setOption('no-background', true);
$snappy->setOption('allow', array('/path1', '/path2'));
$snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2'));
$snappy->setOption('post', array('key' => 'value'));
$snappy->setOption('cover', 'pathToCover.html');
// .. or pass a cover as html
$snappy->setOption('cover', '<h1>Bill cover</h1>');
$snappy->setOption('toc', true);
$snappy->setOption('cache-dir', '/path/to/cache/dir');
Reset options
Options can be reset to their initial values with resetOptions() method.
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
// Set some options
$snappy->setOption('copies' => 4);
// ..
// Reset options
$snappy->resetOptions();
wkhtmltopdf binary as composer dependencies
If you want to download wkhtmltopdf and wkhtmltoimage with composer you add to composer.json:
<?php
use Knp\Snappy\Pdf;
$myProjectDirectory = '/path/to/my/project';
$snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386');
// or
$snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
N.B. These static binaries are extracted from Debian7 packages, so it might not be compatible with non-debian based linux distros
Some use cases
If you want to generate table of contents and you want to use custom XSL stylesheet, do the following:
<?php
$snappy = new Pdf('/path/to/binary');
$snappy->setOption('toc', true);
$snappy->setOption('xsl-style-sheet', 'http://path/to/stylesheet.xsl') //or local file;
$snappy->generateFromHtml('<p>Some content</p>', 'test.pdf');
Bugs & Support
If you found a bug please fill a detailed issue with all the following points.
If you need some help, please at least provide a complete reproducer so we could help you based on facts rather than assumptions.
OS and its version
Wkhtmltopdf, its version and how you installed it
A complete reproducer with relevant php and html/css/js code
If your reproducer is big, please try to shrink it. It will help everyone to narrow the bug.
Maintainers
KNPLabs is looking for maintainers (see why).
If you are interested, feel free to open a PR to ask to be added as a maintainer.
We’ll be glad to hear from you :)
Credits
Snappy has been originally developed by the KnpLabs team.
The most recent commit recorded on KnpLabs/snappy was 3 months ago, based on the GitHub push timestamp. The repository has 438 forks — one of the better signals of community interest.
How many stars does KnpLabs/snappy have?
KnpLabs/snappy has 4.5k GitHub stars — refresh the page for the live number, or check github.com/KnpLabs/snappy. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is KnpLabs/snappy open source?
Yes — KnpLabs/snappy ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/KnpLabs/snappy.
What else is in the Image Tools space?
KnpLabs/snappy is tracked by TopGit under the Image Tools category, alongside 6 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What topics is KnpLabs/snappy associated with?
GitHub's repository topics for KnpLabs/snappy: "hacktoberfest", "html-to-image", "html-to-pdf", "image-generation", "pdf-generation", "php". TopGit's editorial category is Image Tools.
Where can I see KnpLabs/snappy in action?
The project maintains a homepage at https://knplabs.com. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about KnpLabs/snappy?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/KnpLabs/snappy is the definitive source.
Read full README in the tab above.
Is snappy worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of snappy.