PHPackages                             pxlrbt/laravel-pdfable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. pxlrbt/laravel-pdfable

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

pxlrbt/laravel-pdfable
======================

This is my package laravel-pdfable

v0.1.5(2y ago)751.2k9[3 PRs](https://github.com/pxlrbt/laravel-pdfable/pulls)MITPHPPHP ^8.1CI passing

Since Jan 3Pushed 5d ago2 watchersCompare

[ Source](https://github.com/pxlrbt/laravel-pdfable)[ Packagist](https://packagist.org/packages/pxlrbt/laravel-pdfable)[ Docs](https://github.com/pxlrbt/laravel-pdfable)[ RSS](/packages/pxlrbt-laravel-pdfable/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (12)Versions (13)Used By (0)

Laravel Pdfable
===============

[](#laravel-pdfable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2236c211a61aef002e22cd5efa1850aa1030353a884b8019c93495937c30f7f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70786c7262742f6c61726176656c2d70646661626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pxlrbt/laravel-pdfable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b63609d559c3e8d67f8a627887a341a62d82fd6c09a63d80347c7c79b31fbf92/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70786c7262742f6c61726176656c2d70646661626c652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/pxlrbt/laravel-pdfable/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/fed02b2c007630233851c7974906ff78a97353160dc30012e385401c51154691/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70786c7262742f6c61726176656c2d70646661626c652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/pxlrbt/laravel-pdfable/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1f956139ffb09075a2f135d9f9315f0d65cd423c7ce73134def9a08beffe05f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70786c7262742f6c61726176656c2d70646661626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pxlrbt/laravel-pdfable)

Keep the logic for your PDFs in one place like you do with Laravel's Mailables.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require pxlrbt/laravel-pdfable
```

You can publish the config file with:

```
php artisan vendor:publish --tag="pdfable-config"
```

Optionally, you can publish the views using

```
php artisan vendor:publish --tag="pdfable-views"
```

Configuration
-------------

[](#configuration)

Currently two drivers are supported:

- Browsershot (default)
- Wkhtmltopdf (legacy, wkhtmltopdf is deprecated)

### Browsershot Driver

[](#browsershot-driver)

This is the default driver and requires [spatie/browsershot](https://github.com/spatie/browsershot). Please follow the installation instructions for that package.

You can configure the Browsershot driver via `BrowsershotDriver::configureUsing()` in your `AppServiceProvider`:

```
BrowsershotDriver::configureUsing(
    fn (Browsershot $browser) => $browser->setCustomTempPath(storage_path('tmp'))
);
```

### Wkhtmltopdf Driver

[](#wkhtmltopdf-driver)

To use the wkhtmlpdf Driver, make sure `wkhtmltopdf` is installed on your system and globally available.

Then, set the `PDFABLE_DRIVER` option in your `.env` file to `wkhtmltopdf`.

Generating Pdfables
-------------------

[](#generating-pdfables)

You can use the make command to generate a Pdfable class and view.

```
php artisan make:pdf Invoice
```

Usage
-----

[](#usage)

You can directly use, pass or return Pdfables in many places in your app.

### As Files

[](#as-files)

You can store Pdfables via `->store()` method. This will use `outputFile()` method on the class to determine the class name. Optionally, you can pass a custom filename.

```
(new Invoice($order)->store()));
```

### As Responses

[](#as-responses)

You can either stream, download or return your Pdfables HTML for debugging.

#### HTML

[](#html)

To return HTML in a debugging view, just return the Pdfable.

```
Route::get('/invoice/{order}', fn (Order $order) => new Invoice($order));
```

#### Stream

[](#stream)

To stream your Pdfable, add the `->stream()` method.

```
Route::get('/invoice/{order}', fn (Order $order) => (new Invoice($order)->stream()));
```

#### Download

[](#download)

To download your Pdfable, add the `->download()` method. Optionally, you can also override the filename from here.

```
Route::get('/invoice/{order}', fn (Order $order) => (new Invoice($order)->download('custom-filename.pdf')));
```

### As Mailable Attachment

[](#as-mailable-attachment)

To use a Pdfable as a mail attachment, just pass it via `->attach()`. Make sure your mailables/notifications are queued for faster processing.

```
return (new MailMessage)
    ->subject("Your Invoice")
    ->attach(new Invoice($order));
```

### As Jobs

[](#as-jobs)

Pdfs can take some time to create, so you can queue your Pdfables and create them in the background with the known Laravel methods.

```
dispatch(new Invoice($order));
// or
Invoice::dispatch($order);
// ...
```

Writing Pdfables
----------------

[](#writing-pdfables)

Once you have generated a pdfable class, open it up so we can explore its contents. Pdfable class configuration is done in several methods.

### Configuring The View

[](#configuring-the-view)

The view is configured via static `$view` property.

```
class Invoice extends Pdfable
{
    public string $view = 'pdf.task';
}
```

### Configuring The Page/Layout

[](#configuring-the-pagelayout)

You can return a `Page` object to configure the PDF page size, orientation and margins.

```
public function page(): Page
{
    return Page::make()->size(PageSize::A4)->margins('narrow');
}
```

### Passing Additional Data

[](#passing-additional-data)

Pass additional data via the constructor of your Pdfable for later use.

```
public function __construct(
    public Order $order,
    public ?Customer $customer = null,
)
{}
```

### Accessing Data From View

[](#accessing-data-from-view)

Similar to Laravel's Blade Components you can access properties and public methods directly from your view file.

```
Invoice for Order {{ $order->id }}

Total: {{ $getTotal() }}
```

### Configuring The Output File

[](#configuring-the-output-file)

When saving a Pdfable to the disk, you can provide a default path via `filename()` and override the default disk via `$disk` property.

```
public function filename(): string
{
    return "customers/{$this->customer->id}/{$this->order->id}.pdf";
}
```

### Queuing A Pdfable

[](#queuing-a-pdfable)

Pdfables 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()`, ...

Credits
-------

[](#credits)

- [Dennis Koch](https://github.com/pxlrbt)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance65

Regular maintenance activity

Popularity33

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~87 days

Recently: every ~108 days

Total

6

Last Release

739d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/de2f0e928f16fab39bac058ab23744ed045a432404d1275a5a5258acbd368798?d=identicon)[pxlrbt](/maintainers/pxlrbt)

---

Top Contributors

[![pxlrbt](https://avatars.githubusercontent.com/u/22632550?v=4)](https://github.com/pxlrbt "pxlrbt (18 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (17 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (12 commits)")[![tjodalv](https://avatars.githubusercontent.com/u/2622065?v=4)](https://github.com/tjodalv "tjodalv (8 commits)")

---

Tags

laravellaravel-packagepdfpdf-generationphplaravelpxlrbtlaravel-pdfable

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/pxlrbt-laravel-pdfable/health.svg)

```
[![Health](https://phpackages.com/badges/pxlrbt-laravel-pdfable/health.svg)](https://phpackages.com/packages/pxlrbt-laravel-pdfable)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

9903.0M8](/packages/spatie-laravel-pdf)[askdkc/livewire-csv

Add importing large CSV (and TSV) data feature to your Laravel models quickly and easily / Laravelにお手軽にCSVインポート機能(TSV含む、かつ大容量対応)を追加する凄いやつだよ🚀

171.4k](/packages/askdkc-livewire-csv)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
