{"id":15649512,"url":"https://github.com/pxlrbt/laravel-pdfable","last_synced_at":"2025-04-07T07:03:47.143Z","repository":{"id":65153793,"uuid":"584399445","full_name":"pxlrbt/laravel-pdfable","owner":"pxlrbt","description":"Keep your PDFs logic in one place.","archived":false,"fork":false,"pushed_at":"2025-02-03T22:15:58.000Z","size":59,"stargazers_count":43,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-31T06:01:33.359Z","etag":null,"topics":["laravel","laravel-package","pdf","pdf-generation","php"],"latest_commit_sha":null,"homepage":"","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/pxlrbt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-01-02T13:09:13.000Z","updated_at":"2025-03-10T16:57:32.000Z","dependencies_parsed_at":"2023-12-25T23:30:00.952Z","dependency_job_id":"67f50681-d694-4c53-877b-5b82bd806bc5","html_url":"https://github.com/pxlrbt/laravel-pdfable","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":0.6153846153846154,"last_synced_commit":"5dfbe30152ed1090f90d714c6afb2e326a196f2b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pxlrbt%2Flaravel-pdfable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pxlrbt%2Flaravel-pdfable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pxlrbt%2Flaravel-pdfable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pxlrbt%2Flaravel-pdfable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pxlrbt","download_url":"https://codeload.github.com/pxlrbt/laravel-pdfable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608150,"owners_count":20965952,"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":["laravel","laravel-package","pdf","pdf-generation","php"],"created_at":"2024-10-03T12:30:00.670Z","updated_at":"2025-04-07T07:03:47.109Z","avatar_url":"https://github.com/pxlrbt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Pdfable\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/pxlrbt/laravel-pdfable.svg?style=flat-square)](https://packagist.org/packages/pxlrbt/laravel-pdfable)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/pxlrbt/laravel-pdfable/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/pxlrbt/laravel-pdfable/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/pxlrbt/laravel-pdfable/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/pxlrbt/laravel-pdfable/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/pxlrbt/laravel-pdfable.svg?style=flat-square)](https://packagist.org/packages/pxlrbt/laravel-pdfable)\n\nKeep the logic for your PDFs in one place like you do with Laravel's Mailables.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require pxlrbt/laravel-pdfable\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"pdfable-config\"\n```\n\nOptionally, you can publish the views using\n\n```bash\nphp artisan vendor:publish --tag=\"pdfable-views\"\n```\n\n## Configuration\n\nCurrently two drivers are supported:\n\n- Browsershot (default)\n- Wkhtmltopdf (legacy, wkhtmltopdf is deprecated)\n\n### Browsershot Driver\n\nThis is the default driver and requires [spatie/browsershot](https://github.com/spatie/browsershot). Please follow the installation instructions for that package.\n\nYou can configure the Browsershot driver via `BrowsershotDriver::configureUsing()` in your `AppServiceProvider`:\n\n```php\nBrowsershotDriver::configureUsing(\n    fn (Browsershot $browser) =\u003e $browser-\u003esetCustomTempPath(storage_path('tmp'))\n);\n```\n\n### Wkhtmltopdf Driver\n\nTo use the wkhtmlpdf Driver, make sure `wkhtmltopdf` is installed on your system and globally available.\n\nThen, set the `PDFABLE_DRIVER` option in  your `.env` file to `wkhtmltopdf`.\n\n\n## Generating Pdfables\n\nYou can use the make command to generate a Pdfable class and view.\n\n```shell\n\nphp artisan make:pdf Invoice\n\n```\n\n## Usage\n\nYou can directly use, pass or return Pdfables in many places in your app.\n\n### As Files\n\nYou can store Pdfables via `-\u003estore()` method. This will use `outputFile()` method on the class to determine the class name. Optionally, you can pass a custom filename.\n\n```php\n(new Invoice($order)-\u003estore()));\n```\n\n### As Responses\n\nYou can either stream, download or return your Pdfables HTML for debugging.\n\n#### HTML\n\nTo return HTML in a debugging view, just return the Pdfable.\n\n```php\nRoute::get('/invoice/{order}', fn (Order $order) =\u003e new Invoice($order));\n```\n\n#### Stream\n\nTo stream your Pdfable, add the `-\u003estream()` method.\n\n```php\nRoute::get('/invoice/{order}', fn (Order $order) =\u003e (new Invoice($order)-\u003estream()));\n```\n\n#### Download\n\nTo download your Pdfable, add the `-\u003edownload()` method. Optionally, you can also override the filename from here.\n\n```php\nRoute::get('/invoice/{order}', fn (Order $order) =\u003e (new Invoice($order)-\u003edownload('custom-filename.pdf')));\n```\n\n### As Mailable Attachment\n\nTo use a Pdfable as a mail attachment, just pass it via `-\u003eattach()`. Make sure your mailables/notifications are queued for faster processing.\n\n```php\nreturn (new MailMessage)\n    -\u003esubject(\"Your Invoice\")    \n    -\u003eattach(new Invoice($order));\n```\n\n### As Jobs\n\nPdfs can take some time to create, so you can queue your Pdfables and create them in the background with the known Laravel methods.\n\n```php\ndispatch(new Invoice($order));\n// or\nInvoice::dispatch($order);\n// ...\n```\n\n## Writing Pdfables\n\nOnce you have generated a pdfable class, open it up so we can explore its contents. Pdfable class configuration is done in several methods.\n\n### Configuring The View\n\nThe view is configured via static `$view` property.\n\n```php\nclass Invoice extends Pdfable\n{\n    public string $view = 'pdf.task';\n}\n```\n\n### Configuring The Page/Layout\n\nYou can return a `Page` object to configure the PDF page size, orientation and margins. \n\n```php\npublic function page(): Page\n{\n    return Page::make()-\u003esize(PageSize::A4)-\u003emargins('narrow');\n}\n```\n\n### Passing Additional Data\n\nPass additional data via the constructor of your Pdfable for later use.\n\n```php\npublic function __construct(\n    public Order $order,\n    public ?Customer $customer = null,\n)\n{}\n```\n\n### Accessing Data From View\n\nSimilar to Laravel's Blade Components you can access properties and public methods directly from your view file.\n\n```html\n\u003ch1\u003eInvoice for Order {{ $order-\u003eid }}\u003c/h1\u003e\n\n\u003cdiv\u003eTotal: {{ $getTotal() }}\u003c/div\u003e  \n```\n\n### Configuring The Output File\n\nWhen saving a Pdfable to the disk, you can provide a default path via `filename()` and override the default disk via `$disk` property. \n\n```php\npublic function filename(): string\n{\n    return \"customers/{$this-\u003ecustomer-\u003eid}/{$this-\u003eorder-\u003eid}.pdf\";\n}\n```\n\n### Queuing A Pdfable\n\nPdfables implement `ShouldQueue` and therefore can be pushed to a queue via `Invoice::dispatch()`. You can also use other queue configuration methods directly on your Pdfable like `backoff()`, `retryUntil()`, `uniqueId()`, ...\n\n## Credits\n\n- [Dennis Koch](https://github.com/pxlrbt)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpxlrbt%2Flaravel-pdfable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpxlrbt%2Flaravel-pdfable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpxlrbt%2Flaravel-pdfable/lists"}