Description
Pdf provides a small Laravel Enso wrapper around Snappy / wkhtmltopdf for generating PDF documents from Blade views.
The package exposes a fluent Pdf service that applies Enso's default page settings, loads a view with data, and then lets the caller inline, download, save, or output the rendered PDF.
It is used across the ecosystem for invoices, orders, delivery notes, stock documents, and other printable documents that need a consistent PDF pipeline.
Installation
Install the package:
composer require laravel-enso/pdf
The package relies on barryvdh/laravel-snappy, which in turn requires a working wkhtmltopdf binary in the target environment.
No additional provider registration is needed beyond Composer's package discovery.
Features
- Wraps
barryvdh/laravel-snappyin a small fluent service. - Loads Blade views with arbitrary data before rendering.
- Streams PDFs inline in the browser.
- Supports file download responses.
- Supports saving generated PDFs to disk.
- Exposes raw PDF output as a string.
- Ships with Enso defaults for paper size, margins, orientation, and footer pagination.
Usage
Generate a PDF from a Blade view:
use LaravelEnso\Pdf\Services\Pdf;
return (new Pdf())
->loadView('documents.order', ['order' => $order])
->inline('order.pdf');
Download instead of inlining:
return (new Pdf())
->loadView('documents.invoice', ['invoice' => $invoice])
->download('invoice.pdf');
Save the generated file:
(new Pdf())
->loadView('documents.note', ['model' => $model])
->save(storage_path('app/temp/document.pdf'));
Switch to landscape and override options when needed:
$pdf = (new Pdf())
->landscape()
->setOption('margin-top', 5)
->loadView('documents.report', ['report' => $report]);
Note
This package is only a wrapper around Snappy. Rendering still depends on the availability and correctness of the underlying wkhtmltopdf binary in the running environment.
API
Contracts
LaravelEnso\Pdf\Contracts\GeneratesPdfLaravelEnso\Pdf\Contracts\SavesPdf
GeneratesPdf defines:
inline(): Responseoutput(): string
SavesPdf defines:
save()
Pdf Service
LaravelEnso\Pdf\Services\Pdf
Public methods:
__construct()inline(string $filename = 'document.pdf'): Responseoutput(): stringsave($filename, $overwrite = false): PdfWrapperdownload(string $filename): Responselandscape(): selfsetOption(string $option, $value): selfloadView(string $view, array $attributes): self
Default options applied in the factory:
paper: a4orientation: portraitmargin-top: 10margin-left: 5margin-right: 5margin-bottom: 10footer-font-size: 8footer-center: "Page [page] from [toPage]"
Depends On
Framework dependency:
External dependencies:
Contributions
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!