Install the package and use the facade. That is the whole setup on Laravel 13 — there is no config/app.php step:
composer require barryvdh/laravel-dompdf
use Barryvdh\DomPDF\Facade\Pdf;
return Pdf::loadView('pdf.invoice', $data)
->setPaper('a4', 'portrait')
->download('invoice-1042.pdf');
What I did and did not run: the composer require above was never executed and no PDF was generated. The package facts below are read from its packagist entry and from its composer.json and CI workflow at the v3.1.2 tag. Everything about Laravel itself was executed against a throwaway Laravel 13.24.0 application on PHP 8.5.8. The package itself is installed only if you set HW_ALLOW_INSTALL=1 when you run laravel-pdf-generator-dompdf.sh; without it the script repeats the packagist, CI-matrix, config/app.php, route and controller checks below, and with it the script also renders a PDF, checks for the %PDF- header and reads the isRemoteEnabled and isPhpEnabled defaults.
Table of Contents
Version and compatibility, from the package’s own files
latest stable = v3.1.2
abandoned = False
php constraint = ^8.1
dompdf/dompdf = ^3.0
illuminate/support = ^9|^10|^11|^12|^13.0
^8.1 admits PHP 8.5, and ^13.0 admits Laravel 13, but a constraint is a promise rather than a test — so here is the test. The .github/workflows/run-tests.yml committed at the v3.1.2 tag runs:
matrix:
php: [8.1, 8.2, 8.3, 8.4, 8.5]
laravel: ['9.*', '10.*', '11.*', '12.*', '13.*']
with PHP 8.1 and 8.2 excluded for Laravel 13. PHP 8.5 with Laravel 13 is a combination the maintainers actually exercise in CI. On the PHP side, dompdf/dompdf needs ext-dom and ext-mbstring; both were present on the PHP 8.5.8 build used here.
The config/app.php step no longer exists
The provider and alias arrays are gone from config/app.php. The full set of top-level keys in a Laravel 13 config/app.php is:
name env debug url timezone locale fallback_locale faker_locale cipher key previous_keys maintenance
Application service providers now live in bootstrap/providers.php, and packages do not go there either. The package declares its own wiring, which Composer’s auto-discovery reads after install:
"extra": {
"laravel": {
"providers": ["Barryvdh\\DomPDF\\ServiceProvider"],
"aliases": { "Pdf": "Barryvdh\\DomPDF\\Facade\\Pdf", "PDF": "Barryvdh\\DomPDF\\Facade\\Pdf" }
}
}
Note both aliases resolve to Barryvdh\DomPDF\Facade\Pdf. Barryvdh\DomPDF\Facade::class has not been the facade class since v2.
Route and controller, in current syntax
This route fails immediately on Laravel 13:
Route::get('/legacy-pdf', 'PDFController@generatePDF');
$ php artisan route:list
ReflectionException
Class "PDFController" does not exist
Laravel 8 removed the implicit App\Http\Controllers prefix, so controllers are referenced by class. An invokable controller is the natural shape for a single-action route:
// routes/web.php
use App\Http\Controllers\InvoicePdfController;
Route::get('/invoice/pdf', InvoicePdfController::class)->name('invoice.pdf');
// app/Http/Controllers/InvoicePdfController.php
namespace App\Http\Controllers;
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Http\Response;
class InvoicePdfController extends Controller
{
public function __invoke(): Response
{
$data = ['number' => 'INV-1042', 'total' => '129.00'];
return Pdf::loadView('pdf.invoice', $data)
->setPaper('a4', 'portrait')
->download('invoice-1042.pdf');
}
}
{{-- resources/views/pdf/invoice.blade.php --}}
<!doctype html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<h1>Invoice {{ $number }}</h1>
<p>Total: {{ $total }}</p>
</body>
</html>
That route registers cleanly with no provider edits — route:list shows invoice.pdf › InvoicePdfController. Until the package is installed, hitting it produces exactly one error, which is a useful thing to recognise:
Error: Class "Barryvdh\DomPDF\Facade\Pdf" not found
That means the package is missing, not that your alias is wrong. The <meta charset> tag in the view is not decoration — dompdf mis-renders UTF-8 without it, which is the most common “my accents turned into question marks” bug.
The DomPDF options worth knowing
Publish the config with php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider" and you get config/dompdf.php. Three settings there decide whether this feature is a report generator or a hole in your server:
isRemoteEnabled— lets the renderer fetch<img src="http://...">and remote stylesheets. The README states it has been disabled by default since 3.x, “to provide more security”. If any part of the HTML comes from a user, leaving it off is what stops a PDF request from being turned into a server-side request forgery against your internal network or cloud metadata endpoint. If you genuinely need remote images, use theallowedRemoteHostsallowlist rather than switching the flag on globally.isPhpEnabled— defaults tofalse, and executes inline PHP in the document when true. On user-supplied HTML that is remote code execution. There is no safe use of this on untrusted input.chroot— defaults to the application directory and bounds which local files the renderer may read. Widening it to/turns<img src="/etc/passwd">-style tricks into a file read.
Beyond that, the useful everyday knobs are setPaper('a4', 'landscape'), CSS page-break-after: always for explicit page breaks, ->output() to get the bytes as a string instead of a response, and ->stream() to display inline rather than download.
Test it without rendering it
PDF generation is slow and the output is hard to assert on, so mock the facade and check that your controller asked for the right thing:
Pdf::shouldReceive('loadView')->once()->with('pdf.invoice', \Mockery::type('array'))->andReturnSelf();
Pdf::shouldReceive('setPaper')->once()->andReturnSelf();
Pdf::shouldReceive('download')->once()->with('invoice-1042.pdf')->andReturn(response('', 200));
$this->get('/invoice/pdf')->assertOk();
Keep one integration test that actually renders and asserts the file begins with the bytes %PDF-; that is the only assertion about the output worth making.