Skip to content

Framework integration

NextPDF Laravel

First-class Laravel 12 integration—Facade, responses, and queued generation.

Free · Apache-2.0Laravel ^12.0 · NextPDF ^3.0 || ^5.2 · PHP >=8.4 <9.0

NextPDF Laravel provides first-class Laravel 12 integration for NextPDF. It ships with auto-discovery, a Pdf Facade, streaming download and inline preview responses, queued generation for heavy workloads, and automatic detection of installed extensions (NextPDF Artisan, NextPDF Pro). Designed to be Octane-safe and Reverb-compatible out of the box.

How it fits

Built into your workflow

Registered through Laravel package discovery

Laravel package discovery wires NextPDF into the container automatically—the service provider, the Pdf Facade, and the response helpers register themselves, so your first PDF uses the package defaults directly.

Heavy documents, off the request

Dispatch GeneratePdfJob to your queue and a background worker renders the document out-of-band. You hand it a builder class and a context array; it produces the file in the background and keeps the web request responsive—ideal for month-end reports and batch runs.

Safe under Octane and Reverb

Singleton registries are guarded with locks and LRU caching, while every request resolves a fresh Document from the factory. Long-running Octane and Reverb workers reuse the expensive parts while each request keeps its mutable document state in that fresh instance.

Get started

Install

terminal
composer require nextpdf/laravel

In code

How it works

Facade usage

php
use NextPDF\Laravel\Facades\Pdf;

// Facade resolves a fresh Document from the container (DocumentFactory)
Pdf::addPage();
Pdf::cell(0, 10, 'Hello from Laravel!', newLine: true);
Pdf::save('/path/to/hello.pdf');

Download response

php
use NextPDF\Contracts\PdfDocumentInterface;
use NextPDF\Laravel\Http\PdfResponse;

public function download(Invoice $invoice): \Illuminate\Http\Response
{
    $doc = app(PdfDocumentInterface::class);
    $doc->addPage();
    $doc->cell(0, 10, "Invoice #{$invoice->number}", newLine: true);

    return PdfResponse::download($doc, "invoice-{$invoice->number}.pdf");
}

Queued generation by builder class

php
use NextPDF\Laravel\Jobs\GeneratePdfJob;

GeneratePdfJob::dispatch(
    builderClass: MonthlyReportBuilder::class,
    outputPath: storage_path('reports/january-2026.pdf'),
    builderContext: ['revenue' => '$124,500'],
);

Capabilities

What you get

  • Auto-discovery—registration through Laravel package discovery
  • Pdf Facade—expressive, static-proxy API for creating documents
  • PdfResponse—download, inline, and streamed responses with OWASP headers
  • GeneratePdfJob—dispatch PDF generation to background queues
  • Extension detection—Artisan and Pro auto-configured when installed
  • Octane / Reverb safe—singleton registries with lock and LRU; Document is always fresh

When to use it

Reach for this when you are building on Laravel 12. The package registers PDF generation with the container, response helpers, and queue integration, and carries lifecycle controls for Octane and Reverb.