[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8396":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":17,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":33,"discoverSource":34},8396,"snappy","KnpLabs\u002Fsnappy","KnpLabs","PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf\u002Fwkhtmltoimage","https:\u002F\u002Fknplabs.com",null,"PHP",4473,435,128,6,0,2,7,29.92,"MIT License",false,"master",[24,25,26,27,28,29],"hacktoberfest","html-to-image","html-to-pdf","image-generation","pdf-generation","php","2026-06-12 02:01:53","# Snappy\n\n![Build Status](https:\u002F\u002Fgithub.com\u002FKnpLabs\u002Fsnappy\u002Factions\u002Fworkflows\u002Fbuild.yaml\u002Fbadge.svg)\n[![AppVeyor CI Build Status](https:\u002F\u002Fci.appveyor.com\u002Fapi\u002Fprojects\u002Fstatus\u002Fgithub\u002FKnpLabs\u002Fsnappy?branch=master&svg=true)](https:\u002F\u002Fci.appveyor.com\u002Fproject\u002FNiR-\u002Fsnappy)\n[![Scrutinizer Code Quality](https:\u002F\u002Fscrutinizer-ci.com\u002Fg\u002FKnpLabs\u002FGaufrette\u002Fbadges\u002Fquality-score.png?b=master)](https:\u002F\u002Fscrutinizer-ci.com\u002Fg\u002FKnpLabs\u002FGaufrette\u002F?branch=master)\n\nSnappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page.\nIt uses the excellent webkit-based [wkhtmltopdf and wkhtmltoimage](http:\u002F\u002Fwkhtmltopdf.org\u002F)\navailable on OSX, linux, windows.\n\nYou will have to download wkhtmltopdf `0.12.x` in order to use Snappy.\n\nPlease, check [FAQ](doc\u002Ffaq.md) before opening a new issue. Snappy is a tiny wrapper around wkhtmltox, so lots of issues are already answered, resolved or wkhtmltox ones.\n\nFollowing integrations are available:\n* [`knplabs\u002Fknp-snappy-bundle`](https:\u002F\u002Fgithub.com\u002FKnpLabs\u002FKnpSnappyBundle), for Symfony\n* [`barryvdh\u002Flaravel-snappy`](https:\u002F\u002Fgithub.com\u002Fbarryvdh\u002Flaravel-snappy), for Laravel\n* [`mvlabs\u002Fmvlabs-snappy`](https:\u002F\u002Fgithub.com\u002Fmvlabs\u002FMvlabsSnappy), for Zend Framework\n\n## Installation using [Composer](http:\u002F\u002Fgetcomposer.org\u002F)\n\n```bash\ncomposer require knplabs\u002Fknp-snappy\n```\n\n## Usage\n\n> ⚠️ **Security Warning**\n>\n> The `--enable-local-file-access` option in `wkhtmltopdf` can be risky if used with untrusted HTML or JavaScript.\n> This may expose local files or lead to remote code execution.\n>\n> To stay safe:\n> - Avoid enabling `--enable-local-file-access` unless necessary.\n> - Always sanitize user input before processing.\n> - Run `wkhtmltopdf` in a sandbox like **AppArmor** or **SELinux**.\n> - For untrusted content, consider alternatives like **WeasyPrint**, **Prince**, or **Puppeteer**.\n>\n> This risk was responsibly reported by  \n> **Nikita Sveshnikov (Positive Technologies)**.\n>\n> 🔗 [Official recommendations](https:\u002F\u002Fwkhtmltopdf.org\u002Fstatus.html#recommendations)\n\n\n### Initialization\n```php\n\u003C?php\n\nrequire __DIR__ . '\u002Fvendor\u002Fautoload.php';\n\nuse Knp\\Snappy\\Pdf;\n\n$snappy = new Pdf('\u002Fusr\u002Flocal\u002Fbin\u002Fwkhtmltopdf');\n\n\u002F\u002F or you can do it in two steps\n$snappy = new Pdf();\n$snappy->setBinary('\u002Fusr\u002Flocal\u002Fbin\u002Fwkhtmltopdf');\n```\n\n### Display the pdf in the browser\n\n```php\n$snappy = new Pdf('\u002Fusr\u002Flocal\u002Fbin\u002Fwkhtmltopdf');\nheader('Content-Type: application\u002Fpdf');\necho $snappy->getOutput('http:\u002F\u002Fwww.github.com');\n```\n\n### Download the pdf from the browser\n\n```php\n$snappy = new Pdf('\u002Fusr\u002Flocal\u002Fbin\u002Fwkhtmltopdf');\nheader('Content-Type: application\u002Fpdf');\nheader('Content-Disposition: attachment; filename=\"file.pdf\"');\necho $snappy->getOutput('http:\u002F\u002Fwww.github.com');\n```\n\n### Merge multiple urls into one pdf\n```php\n$snappy = new Pdf('\u002Fusr\u002Flocal\u002Fbin\u002Fwkhtmltopdf');\nheader('Content-Type: application\u002Fpdf');\nheader('Content-Disposition: attachment; filename=\"file.pdf\"');\necho $snappy->getOutput(array('http:\u002F\u002Fwww.github.com','http:\u002F\u002Fwww.knplabs.com','http:\u002F\u002Fwww.php.net'));\n```\n\n### Generate local pdf file\n```php\n$snappy = new Pdf('\u002Fusr\u002Flocal\u002Fbin\u002Fwkhtmltopdf');\n$snappy->generateFromHtml('\u003Ch1>Bill\u003C\u002Fh1>\u003Cp>You owe me money, dude.\u003C\u002Fp>', '\u002Ftmp\u002Fbill-123.pdf');\n```\n\n### Pass options to snappy\n```php\n\u002F\u002F Type wkhtmltopdf -H to see the list of options\n$snappy = new Pdf('\u002Fusr\u002Flocal\u002Fbin\u002Fwkhtmltopdf');\n$snappy->setOption('disable-javascript', true);\n$snappy->setOption('no-background', true);\n$snappy->setOption('allow', array('\u002Fpath1', '\u002Fpath2'));\n$snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2'));\n$snappy->setOption('post', array('key' => 'value'));\n$snappy->setOption('cover', 'pathToCover.html');\n\u002F\u002F .. or pass a cover as html\n$snappy->setOption('cover', '\u003Ch1>Bill cover\u003C\u002Fh1>');\n$snappy->setOption('toc', true);\n$snappy->setOption('cache-dir', '\u002Fpath\u002Fto\u002Fcache\u002Fdir');\n```\n\n### Reset options\nOptions can be reset to their initial values with `resetOptions()` method.\n```php\n$snappy = new Pdf('\u002Fusr\u002Flocal\u002Fbin\u002Fwkhtmltopdf');\n\u002F\u002F Set some options\n$snappy->setOption('copies' => 4);\n\u002F\u002F ..\n\u002F\u002F Reset options\n$snappy->resetOptions();\n```\n\n## wkhtmltopdf binary as composer dependencies\n\nIf you want to download wkhtmltopdf and wkhtmltoimage with composer you add to `composer.json`:\n\n```bash\ncomposer require h4cc\u002Fwkhtmltopdf-i386 0.12.x\ncomposer require h4cc\u002Fwkhtmltoimage-i386 0.12.x\n```\n\nor this if you are in 64 bit based system:\n\n```bash\ncomposer require h4cc\u002Fwkhtmltopdf-amd64 0.12.x\ncomposer require h4cc\u002Fwkhtmltoimage-amd64 0.12.x\n```\n\nAnd then you can use it\n\n```php\n\u003C?php\n\nuse Knp\\Snappy\\Pdf;\n\n$myProjectDirectory = '\u002Fpath\u002Fto\u002Fmy\u002Fproject';\n\n$snappy = new Pdf($myProjectDirectory . '\u002Fvendor\u002Fh4cc\u002Fwkhtmltopdf-i386\u002Fbin\u002Fwkhtmltopdf-i386');\n\n\u002F\u002F or\n\n$snappy = new Pdf($myProjectDirectory . '\u002Fvendor\u002Fh4cc\u002Fwkhtmltopdf-amd64\u002Fbin\u002Fwkhtmltopdf-amd64');\n```\n\n*N.B.* These static binaries are extracted from  [Debian7 packages](https:\u002F\u002Fgithub.com\u002Fh4cc\u002Fwkhtmltopdf-amd64\u002Fissues\u002F13#issuecomment-150948179), so it might not be compatible with non-debian based linux distros\n## Some use cases\n\nIf you want to generate table of contents and you want to use custom XSL stylesheet, do the following:\n\n```php\n\u003C?php\n$snappy = new Pdf('\u002Fpath\u002Fto\u002Fbinary');\n\n$snappy->setOption('toc', true);\n$snappy->setOption('xsl-style-sheet', 'http:\u002F\u002Fpath\u002Fto\u002Fstylesheet.xsl') \u002F\u002For local file;\n\n$snappy->generateFromHtml('\u003Cp>Some content\u003C\u002Fp>', 'test.pdf');\n```\n\n## Bugs & Support\n\nIf you found a bug please fill a detailed issue with all the following points.\nIf you need some help, please at least provide a complete reproducer so we could help you based on facts rather than assumptions.\n\n* OS and its version\n* Wkhtmltopdf, its version and how you installed it\n* A complete reproducer with relevant php and html\u002Fcss\u002Fjs code\n\nIf your reproducer is big, please try to shrink it. It will help everyone to narrow the bug.\n\n## Maintainers\n\nKNPLabs is looking for maintainers ([see why](https:\u002F\u002Fknplabs.com\u002Fen\u002Fblog\u002Fnews-for-our-foss-projects-maintenance)).\n\nIf you are interested, feel free to open a PR to ask to be added as a maintainer.\n\nWe’ll be glad to hear from you :)\n\n## Credits\n\nSnappy has been originally developed by the [KnpLabs](http:\u002F\u002Fknplabs.com) team.\n","Snappy 是一个 PHP 库，可以从 URL 或 HTML 页面生成缩略图、快照或 PDF 文件。它基于 Webkit 的 wkhtmltopdf 和 wkhtmltoimage 工具，支持在 OSX、Linux 和 Windows 上运行。核心功能包括从网页生成 PDF 或图像，以及将多个 URL 合并为一个 PDF 文件。该库提供了一个简单的接口来调用 wkhtmltopdf 和 wkhtmltoimage，并且有针对 Symfony、Laravel 和 Zend Framework 的集成包。适用于需要动态生成文档的 Web 应用场景，如报表生成、在线文档转换等。需要注意的是，在处理不受信任的内容时，应遵循安全建议以避免潜在风险。","2026-06-11 03:17:42","top_language"]