{"id":13398194,"url":"https://github.com/KnpLabs/snappy","last_synced_at":"2025-03-14T02:30:42.617Z","repository":{"id":945921,"uuid":"723980","full_name":"KnpLabs/snappy","owner":"KnpLabs","description":"PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage","archived":false,"fork":false,"pushed_at":"2025-01-15T07:34:14.000Z","size":538,"stargazers_count":4422,"open_issues_count":11,"forks_count":436,"subscribers_count":131,"default_branch":"master","last_synced_at":"2025-03-10T05:13:43.882Z","etag":null,"topics":["hacktoberfest","html-to-image","html-to-pdf","image-generation","pdf-generation","php"],"latest_commit_sha":null,"homepage":"https://knplabs.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KnpLabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-06-16T13:39:52.000Z","updated_at":"2025-03-10T04:03:42.000Z","dependencies_parsed_at":"2023-07-07T13:16:29.419Z","dependency_job_id":"c970689a-06c5-4b6e-8039-0823cf310f8d","html_url":"https://github.com/KnpLabs/snappy","commit_stats":{"total_commits":311,"total_committers":96,"mean_commits":"3.2395833333333335","dds":0.9067524115755627,"last_synced_commit":"5388a1a8026b670a15b479f6d07dc0e04724af25"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2Fsnappy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2Fsnappy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2Fsnappy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2Fsnappy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KnpLabs","download_url":"https://codeload.github.com/KnpLabs/snappy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243511566,"owners_count":20302575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","html-to-image","html-to-pdf","image-generation","pdf-generation","php"],"created_at":"2024-07-30T19:00:19.795Z","updated_at":"2025-03-14T02:30:42.294Z","avatar_url":"https://github.com/KnpLabs.png","language":"PHP","readme":"# Snappy\n\n![Build Status](https://github.com/KnpLabs/snappy/actions/workflows/build.yaml/badge.svg)\n[![AppVeyor CI Build Status](https://ci.appveyor.com/api/projects/status/github/KnpLabs/snappy?branch=master\u0026svg=true)](https://ci.appveyor.com/project/NiR-/snappy)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/KnpLabs/Gaufrette/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/KnpLabs/Gaufrette/?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://wkhtmltopdf.org/)\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/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.\n\nFollowing integrations are available:\n* [`knplabs/knp-snappy-bundle`](https://github.com/KnpLabs/KnpSnappyBundle), for Symfony\n* [`barryvdh/laravel-snappy`](https://github.com/barryvdh/laravel-snappy), for Laravel\n* [`mvlabs/mvlabs-snappy`](https://github.com/mvlabs/MvlabsSnappy), for Zend Framework\n\n## Installation using [Composer](http://getcomposer.org/)\n\n```bash\ncomposer require knplabs/knp-snappy\n```\n\n## Usage\n\n### Initialization\n```php\n\u003c?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Knp\\Snappy\\Pdf;\n\n$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');\n\n// or you can do it in two steps\n$snappy = new Pdf();\n$snappy-\u003esetBinary('/usr/local/bin/wkhtmltopdf');\n```\n\n### Display the pdf in the browser\n\n```php\n$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');\nheader('Content-Type: application/pdf');\necho $snappy-\u003egetOutput('http://www.github.com');\n```\n\n### Download the pdf from the browser\n\n```php\n$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');\nheader('Content-Type: application/pdf');\nheader('Content-Disposition: attachment; filename=\"file.pdf\"');\necho $snappy-\u003egetOutput('http://www.github.com');\n```\n\n### Merge multiple urls into one pdf\n```php\n$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');\nheader('Content-Type: application/pdf');\nheader('Content-Disposition: attachment; filename=\"file.pdf\"');\necho $snappy-\u003egetOutput(array('http://www.github.com','http://www.knplabs.com','http://www.php.net'));\n```\n\n### Generate local pdf file\n```php\n$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');\n$snappy-\u003egenerateFromHtml('\u003ch1\u003eBill\u003c/h1\u003e\u003cp\u003eYou owe me money, dude.\u003c/p\u003e', '/tmp/bill-123.pdf');\n```\n\n### Pass options to snappy\n```php\n// Type wkhtmltopdf -H to see the list of options\n$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');\n$snappy-\u003esetOption('disable-javascript', true);\n$snappy-\u003esetOption('no-background', true);\n$snappy-\u003esetOption('allow', array('/path1', '/path2'));\n$snappy-\u003esetOption('cookie', array('key' =\u003e 'value', 'key2' =\u003e 'value2'));\n$snappy-\u003esetOption('post', array('key' =\u003e 'value'));\n$snappy-\u003esetOption('cover', 'pathToCover.html');\n// .. or pass a cover as html\n$snappy-\u003esetOption('cover', '\u003ch1\u003eBill cover\u003c/h1\u003e');\n$snappy-\u003esetOption('toc', true);\n$snappy-\u003esetOption('cache-dir', '/path/to/cache/dir');\n```\n\n### Reset options\nOptions can be reset to their initial values with `resetOptions()` method.\n```php\n$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');\n// Set some options\n$snappy-\u003esetOption('copies' =\u003e 4);\n// ..\n// Reset options\n$snappy-\u003eresetOptions();\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/wkhtmltopdf-i386 0.12.x\ncomposer require h4cc/wkhtmltoimage-i386 0.12.x\n```\n\nor this if you are in 64 bit based system:\n\n```bash\ncomposer require h4cc/wkhtmltopdf-amd64 0.12.x\ncomposer require h4cc/wkhtmltoimage-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 = '/path/to/my/project';\n\n$snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386');\n\n// or\n\n$snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');\n```\n\n*N.B.* These static binaries are extracted from  [Debian7 packages](https://github.com/h4cc/wkhtmltopdf-amd64/issues/13#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('/path/to/binary');\n\n$snappy-\u003esetOption('toc', true);\n$snappy-\u003esetOption('xsl-style-sheet', 'http://path/to/stylesheet.xsl') //or local file;\n\n$snappy-\u003egenerateFromHtml('\u003cp\u003eSome content\u003c/p\u003e', 'test.pdf');\n```\n\n## Bugs \u0026 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/css/js 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://knplabs.com/en/blog/news-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://knplabs.com) team.\n","funding_links":[],"categories":["PHP","Table of Contents","PDF","目录","PDF PDF","类库","Libraries"],"sub_categories":["PDF","PDF/条形码","PHP"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKnpLabs%2Fsnappy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKnpLabs%2Fsnappy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKnpLabs%2Fsnappy/lists"}