safermobility/laravel-gotenberg

Create PDFs in Laravel apps using Gotenberg

v1.0.0 2025-04-01 15:47 UTC

This package is auto-updated.

Last update: 2025-04-01 15:48:58 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a simple way to create PDFs in Laravel apps. Under the hood it uses Gotenberg to generate PDFs from Blade views. You can use modern CSS features like grid and flexbox to create beautiful PDFs.

This package is very heavily based on Spatie's laravel-pdf package, but does not require Node.js to run, making it more suitable for applications that run in containers.

Installation

You can install the package via composer:

composer require safermobility/laravel-gotenberg

You can publish the config file with:

php artisan vendor:publish --tag="laravel-gotenberg-config"

This is the contents of the published config file:

return [
    'host' => env('GOTENBERG_HOST'),
];

Usage

You must have a working Gotenberg instance.

For development, you may be able to use the Gotenberg Demo server:

GOTENBERG_HOST=https://demo.gotenberg.dev

For production, you must set up your own Gotenberg instance.

Simple PDF generation

use SaferMobility\LaravelGotenberg\Facades\Gotenberg;

Gotenberg::view('pdfs.invoice', ['invoice' => $invoice])
    ->format('letter')
    ->save('invoice.pdf')

This will render the Blade view pdfs.invoice with the given data and save it as a PDF file.

You can also return the PDF as a response from your controller:

use SaferMobility\LaravelGotenberg\Facades\Gotenberg;

class DownloadInvoiceController
{
    public function __invoke(Invoice $invoice)
    {
        return Gotenberg::view('pdfs.invoice', ['invoice' => $invoice])
            ->format('letter')
            ->name('your-invoice.pdf');
    }
}

This will use a streamed response to reduce memory usage.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.