{"id":13396083,"url":"https://github.com/barryvdh/laravel-snappy","last_synced_at":"2025-05-14T07:07:36.543Z","repository":{"id":12611115,"uuid":"15282186","full_name":"barryvdh/laravel-snappy","owner":"barryvdh","description":"Laravel Snappy PDF","archived":false,"fork":false,"pushed_at":"2025-02-24T15:20:46.000Z","size":98,"stargazers_count":2702,"open_issues_count":49,"forks_count":291,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-05-07T06:37:14.631Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/barryvdh.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"barryvdh","custom":["https://fruitcake.nl"]}},"created_at":"2013-12-18T12:09:11.000Z","updated_at":"2025-05-04T03:40:27.000Z","dependencies_parsed_at":"2024-01-17T07:59:56.092Z","dependency_job_id":"59fc38a5-4c2a-4ef4-84c0-b2d5a15f7fd0","html_url":"https://github.com/barryvdh/laravel-snappy","commit_stats":{"total_commits":106,"total_committers":44,"mean_commits":2.409090909090909,"dds":0.5283018867924528,"last_synced_commit":"940eec2d99b89cbc9bea2f493cf068382962a485"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-snappy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-snappy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-snappy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-snappy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barryvdh","download_url":"https://codeload.github.com/barryvdh/laravel-snappy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092648,"owners_count":22013290,"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":[],"created_at":"2024-07-30T18:00:39.380Z","updated_at":"2025-05-14T07:07:36.487Z","avatar_url":"https://github.com/barryvdh.png","language":"PHP","funding_links":["https://github.com/sponsors/barryvdh","https://fruitcake.nl"],"categories":["Popular Packages","PHP","Paquetes utiles","目录","PDF"],"sub_categories":["PDF"],"readme":"## Snappy PDF/Image Wrapper for Laravel\n[![Tests](https://github.com/barryvdh/laravel-snappy/workflows/Tests/badge.svg)](https://github.com/barryvdh/laravel-snappy/actions)\n[![Packagist License](https://poser.pugx.org/barryvdh/laravel-snappy/license.png)](http://choosealicense.com/licenses/mit/)\n[![Latest Stable Version](https://poser.pugx.org/barryvdh/laravel-snappy/version.png)](https://packagist.org/packages/barryvdh/laravel-snappy)\n[![Total Downloads](https://poser.pugx.org/barryvdh/laravel-snappy/d/total.png)](https://packagist.org/packages/barryvdh/laravel-snappy)\n[![Fruitcake](https://img.shields.io/badge/Powered%20By-Fruitcake-b2bc35.svg)](https://fruitcake.nl/)\n\nThis package is a ServiceProvider for Snappy: [https://github.com/KnpLabs/snappy](https://github.com/KnpLabs/snappy).\n\n### Wkhtmltopdf Installation\n\nChoose one of the following options to install wkhtmltopdf/wkhtmltoimage.\n\n1. Download wkhtmltopdf from [here](http://wkhtmltopdf.org/downloads.html); \n2. Or install as a composer dependency. See [wkhtmltopdf binary as composer dependencies](https://github.com/KnpLabs/snappy#wkhtmltopdf-binary-as-composer-dependencies) for more information.\n\n#### Attention! Please note that some dependencies (libXrender for example) may not be present on your system and may require manual installation. \n\n### Testing the wkhtmltopdf installation\n\nAfter installing you should be able to run wkhtmltopdf from the command line / shell.\n\nIf you went for the second option the binaries will be at `/vendor/h4cc/wkhtmltoimage-amd64/bin` and `/vendor/h4cc/wkhtmltopdf-amd64/bin`. \n\n#### Attention vagrant users!\n\nMove the binaries to a path that is not in a synced folder, for example:\n\n```bash\ncp vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64 /usr/local/bin/\ncp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 /usr/local/bin/\n```\n\nand make it executable:\n\n```bash\nchmod +x /usr/local/bin/wkhtmltoimage-amd64 \nchmod +x /usr/local/bin/wkhtmltopdf-amd64\n```\n\nThis will prevent the error 126.\n\n### Package Installation\n\nRequire this package in your composer.json and update composer.\n\n```bash\ncomposer require barryvdh/laravel-snappy\n```\n\n### Laravel\n\n**Laravel 5.5** uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider/Facade. If you also use laravel-dompdf, watch out for conflicts. It could be better to manually register the Facade.\n\nAfter updating composer, add the ServiceProvider to the providers array in config/app.php\n\n```php\nBarryvdh\\Snappy\\ServiceProvider::class,\n```\n\nOptionally you can use the Facade for shorter code. Add this to your facades:\n\n```php\n'PDF' =\u003e Barryvdh\\Snappy\\Facades\\SnappyPdf::class,\n'SnappyImage' =\u003e Barryvdh\\Snappy\\Facades\\SnappyImage::class,\n```\n\nFinally you can publish the config file:\n\n```bash\nphp artisan vendor:publish --provider=\"Barryvdh\\Snappy\\ServiceProvider\"\n```\n\n### Snappy config file\n\nThe main change to this config file (config/snappy.php) will be the path to the binaries.\n\nFor example, when loaded with composer, the line should look like:\n\n```php\n'binary' =\u003e base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),\n```\n\nIf you followed the vagrant steps, the line should look like:\n\n```php\n'binary'  =\u003e '/usr/local/bin/wkhtmltopdf-amd64',\n```\n\nFor windows users you'll have to add double quotes to the bin path for wkhtmltopdf:\n\n```php\n'binary' =\u003e '\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf\"'\n```\n\n### Lumen\nIn `bootstrap/app.php` add:\n\n```php\nclass_alias('Barryvdh\\Snappy\\Facades\\SnappyPdf', 'PDF');\n$app-\u003eregister(Barryvdh\\Snappy\\LumenServiceProvider::class);\n```\n\nOptionally, add the facades like so:\n\n```php\nclass_alias(Barryvdh\\Snappy\\Facades\\SnappyPdf::class, 'PDF');\nclass_alias(Barryvdh\\Snappy\\Facades\\SnappyImage::class, 'SnappyImage');\n```\n\nTo customise the configuration file, copy the file `/vendor/barryvdh/laravel-snappy/config/snappy.php` to the `/config` folder.\n\n### Usage\n\nYou can create a new Snappy PDF/Image instance and load a HTML string, file or view name. You can save it to a file, or inline (show in browser) or download.\n\nUsing the App container:\n\n```php\n$snappy = App::make('snappy.pdf');\n//To file\n$html = '\u003ch1\u003eBill\u003c/h1\u003e\u003cp\u003eYou owe me money, dude.\u003c/p\u003e';\n$snappy-\u003egenerateFromHtml($html, '/tmp/bill-123.pdf');\n$snappy-\u003egenerate('http://www.github.com', '/tmp/github.pdf');\n//Or output:\nreturn new Response(\n    $snappy-\u003egetOutputFromHtml($html),\n    200,\n    array(\n        'Content-Type'          =\u003e 'application/pdf',\n        'Content-Disposition'   =\u003e 'attachment; filename=\"file.pdf\"'\n    )\n);\n```\n\nUsing the wrapper:\n\n```php\n$pdf = App::make('snappy.pdf.wrapper');\n$pdf-\u003eloadHTML('\u003ch1\u003eTest\u003c/h1\u003e');\nreturn $pdf-\u003einline();\n```\n\nOr use the facade:\n\n```php\n$pdf = PDF::loadView('pdf.invoice', $data);\nreturn $pdf-\u003edownload('invoice.pdf');\n```\n\nYou can chain the methods:\n\n```php\nreturn PDF::loadFile('http://www.github.com')-\u003einline('github.pdf');\n```\n\nYou can change the orientation and paper size\n\n```php\nPDF::loadHTML($html)-\u003esetPaper('a4')-\u003esetOrientation('landscape')-\u003esetOption('margin-bottom', 0)-\u003esave('myfile.pdf')\n```\n\nIf you need the output as a string, you can get the rendered PDF with the output() function, so you can save/output it yourself.\n\nSee the [wkhtmltopdf manual](http://wkhtmltopdf.org/usage/wkhtmltopdf.txt) for more information/settings.\n\n### Testing - PDF fake\n\nAs an alternative to mocking, you may use the `PDF` facade's `fake` method. When using fakes, assertions are made after the code under test is executed:\n\n```php\n\u003c?php\n\nnamespace Tests\\Feature;\n\nuse Tests\\TestCase;\nuse PDF;\n\nclass ExampleTest extends TestCase\n{\n    public function testPrintOrderShipping()\n    {\n        PDF::fake();\n        \n        // Perform order shipping...\n        \n        PDF::assertViewIs('view-pdf-order-shipping');\n        PDF::assertSee('Name');\n    }\n}\n```\n\n#### Other available assertions:\n\n```php\nPDF::assertViewIs($value);\nPDF::assertViewHas($key, $value = null);\nPDF::assertViewHasAll(array $bindings);\nPDF::assertViewMissing($key);\nPDF::assertSee($value);\nPDF::assertSeeText($value);\nPDF::assertDontSee($value);\nPDF::assertDontSeeText($value);\nPDF::assertFileNameIs($value);\n```\n\n### License\n\nThis Snappy Wrapper for Laravel is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarryvdh%2Flaravel-snappy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarryvdh%2Flaravel-snappy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarryvdh%2Flaravel-snappy/lists"}