{"id":14983921,"url":"https://github.com/knplabs/knpsnappybundle","last_synced_at":"2025-05-14T02:04:17.400Z","repository":{"id":957782,"uuid":"743218","full_name":"KnpLabs/KnpSnappyBundle","owner":"KnpLabs","description":"Easily create PDF and images in Symfony by converting html using webkit","archived":false,"fork":false,"pushed_at":"2024-09-26T06:21:09.000Z","size":193,"stargazers_count":1235,"open_issues_count":2,"forks_count":143,"subscribers_count":55,"default_branch":"master","last_synced_at":"2024-10-29T10:23:36.623Z","etag":null,"topics":["hacktoberfest","html-to-image","html-to-pdf","image-generation","pdf-generation","php","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"http://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.markdown","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-06-27T11:08:07.000Z","updated_at":"2024-10-13T18:55:53.000Z","dependencies_parsed_at":"2023-07-05T18:49:08.936Z","dependency_job_id":"84a28389-ac93-4ce5-a2b2-0df9fe1f29aa","html_url":"https://github.com/KnpLabs/KnpSnappyBundle","commit_stats":{"total_commits":155,"total_committers":56,"mean_commits":2.767857142857143,"dds":0.8709677419354839,"last_synced_commit":"39ffad9e7294e3c9d87ee5de7da7e4495b055126"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2FKnpSnappyBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2FKnpSnappyBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2FKnpSnappyBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2FKnpSnappyBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KnpLabs","download_url":"https://codeload.github.com/KnpLabs/KnpSnappyBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052679,"owners_count":22006716,"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","symfony","symfony-bundle"],"created_at":"2024-09-24T14:08:10.666Z","updated_at":"2025-05-14T02:04:17.361Z","avatar_url":"https://github.com/KnpLabs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"KnpSnappyBundle\n===============\n\n![Build Status](https://github.com/KnpLabs/KnpSnappyBundle/actions/workflows/build.yaml/badge.svg)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/KnpLabs/KnpSnappyBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/KnpLabs/KnpSnappyBundle/?branch=master)\n[![StyleCI](https://styleci.io/repos/743218/shield?branch=master)](https://styleci.io/repos/743218)\n\n[Snappy][snappy] is a PHP wrapper for the [wkhtmltopdf][wkhtmltopdf] conversion utility.\nIt allows you to generate either pdf or image files from your html documents, using the webkit engine.\n\nThe KnpSnappyBundle provides a simple integration for your Symfony project.\n\nLimitations\n----------\n\nIf you use JavaScript to render your pages, you may encounter some issues because of [wkhtmltopdf][wkhtmltopdf] not being fully compatible with ES6 apis.\nThe only way to solve this issue is to provide polyfills that fix the gaps between modern ES6 apis and the [wkhtmltopdf][wkhtmltopdf] rendering engine.\n\nInstallation\n------------\n\nWith [composer](https://getcomposer.org), require:\n\n```bash\ncomposer require knplabs/knp-snappy-bundle\n```\n\nIf you are not using Flex, enable it in your kernel :\n\n```php\n// config/bundles.php\n\u003c?php\n\nreturn [\n    //...\n    Knp\\Bundle\\SnappyBundle\\KnpSnappyBundle::class =\u003e ['all' =\u003e true],\n    //...\n];\n```\nConfiguration\n-------------\n\nIf you need to change the binaries, change the instance options or even disable one or both services, you can do it through the configuration.\n\n```yaml\n# config/packages/knp_snappy.yaml\nknp_snappy:\n    pdf:\n        enabled:    true\n        binary:     /usr/local/bin/wkhtmltopdf #\"\\\"C:\\\\Program Files\\\\wkhtmltopdf\\\\bin\\\\wkhtmltopdf.exe\\\"\" for Windows users\n        options:    []\n    image:\n        enabled:    true\n        binary:     /usr/local/bin/wkhtmltoimage #\"\\\"C:\\\\Program Files\\\\wkhtmltopdf\\\\bin\\\\wkhtmltoimage.exe\\\"\" for Windows users\n        options:    []\n```\n\nIf you want to change temporary folder which is ```sys_get_temp_dir()``` by default, you can use\n\n```yaml\n# config/packages/knp_snappy.yaml\nknp_snappy:\n    temporary_folder: \"%kernel.cache_dir%/snappy\"\n```\n\nYou can also configure the timeout used by the generators with `process_timeout`:\n\n```yaml\n# config/packages/knp_snappy.yaml\nknp_snappy:\n    process_timeout: 20 # In seconds\n```\n\nUsage\n-----\n\nThe bundle registers two services:\n\n - the `knp_snappy.image` service allows you to generate images;\n - the `knp_snappy.pdf` service allows you to generate pdf files.\n\n### Generate an image from a URL\n\n```php\n// @var Knp\\Snappy\\Image\n$knpSnappyImage-\u003egenerate('http://www.google.fr', '/path/to/the/image.jpg');\n```\n\n### Generate a pdf document from a URL\n\n```php\n// @var \\Knp\\Snappy\\Pdf\n$knpSnappyPdf-\u003egenerate('http://www.google.fr', '/path/to/the/file.pdf');\n```\n\n### Generate a pdf document from multiple URLs\n\n```php\n// @var \\Knp\\Snappy\\Pdf\n$knpSnappyPdf-\u003egenerate(array('http://www.google.fr', 'http://www.knplabs.com', 'http://www.google.com'), '/path/to/the/file.pdf');\n```\n\n### Generate a pdf document from a twig view\n\n```php\n// @var \\Knp\\Snappy\\Pdf\n$knpSnappyPdf-\u003egenerateFromHtml(\n    $this-\u003erenderView(\n        'MyBundle:Foo:bar.html.twig',\n        array(\n            'some'  =\u003e $vars\n        )\n    ),\n    '/path/to/the/file.pdf'\n);\n```\n\n### Render an image as response from a controller\n\n```php\nuse Knp\\Bundle\\SnappyBundle\\Snappy\\Response\\JpegResponse;\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;\n\nclass SomeController extends AbstractController\n{\n    public function imageAction(\\Knp\\Snappy\\Image $knpSnappyImage)\n    {\n        $html = $this-\u003erenderView('MyBundle:Foo:bar.html.twig', array(\n            'some'  =\u003e $vars\n        ));\n\n        return new JpegResponse(\n            $knpSnappyImage-\u003egetOutputFromHtml($html),\n            'image.jpg'\n        );\n    }\n}\n```\n\n### Render a pdf document as response from a controller\n\n```php\nuse Knp\\Bundle\\SnappyBundle\\Snappy\\Response\\PdfResponse;\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;\n\nclass SomeController extends AbstractController\n{\n    public function pdfAction(\\Knp\\Snappy\\Pdf $knpSnappyPdf)\n    {\n        $html = $this-\u003erenderView('MyBundle:Foo:bar.html.twig', array(\n            'some'  =\u003e $vars\n        ));\n\n        return new PdfResponse(\n            $knpSnappyPdf-\u003egetOutputFromHtml($html),\n            'file.pdf'\n        );\n    }\n}\n```\n\n### Render a pdf document with a relative url inside like css files\n\n```php\nuse Knp\\Bundle\\SnappyBundle\\Snappy\\Response\\PdfResponse;\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;\n\nclass SomeController extends AbstractController\n{\n    public function pdfAction(\\Knp\\Snappy\\Pdf $knpSnappyPdf)\n    {\n        $pageUrl = $this-\u003egenerateUrl('homepage', array(), true); // use absolute path!\n\n        return new PdfResponse(\n            $knpSnappyPdf-\u003egetOutput($pageUrl),\n            'file.pdf'\n        );\n    }\n}\n```\n\nMaintainers\n-----------\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\nCredits\n-------\n\nSnappyBundle and [Snappy][snappy] are based on the awesome [wkhtmltopdf][wkhtmltopdf].\nSnappyBundle has been developed by [KnpLabs][KnpLabs].\n\n[snappy]: https://github.com/KnpLabs/snappy\n[wkhtmltopdf]: http://wkhtmltopdf.org\n[KnpLabs]: http://www.knplabs.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknplabs%2Fknpsnappybundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknplabs%2Fknpsnappybundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknplabs%2Fknpsnappybundle/lists"}