# Laravel Dompdf

> Activate when the user is generating, downloading, streaming, saving, or configuring PDFs in a Laravel app with barryvdh/laravel-dompdf. Use for Pdf::loadView(), Pdf::loadHTML(), Pdf::loadFile(), output(), save(), stream(), download(), setPaper(), setOption(), setWarnings(), setPdfA(), addEmbeddedFile(), setAdditionalXmpRdf(), config/dompdf.php, vendor publishing, font configuration, remote asset loading, PDF/A, invoice PDFs, report exports, attachment rendering, or debugging DOMPDF output in Laravel.

- Skill: `barryvdh/laravel-dompdf` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add barryvdh/laravel-dompdf`
- Raw SKILL.md: https://api.skillmd.com/api/skills/barryvdh/laravel-dompdf/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Docs & Writing
- License: MIT
- Author: barryvdh (https://skillmd.com/u/barryvdh)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/barryvdh/laravel-dompdf

---


# Laravel DOMPDF

Use this skill when a Laravel task involves PDF generation through `barryvdh/laravel-dompdf`.

## Documentation

Use `search-docs` when it is available for Laravel integration details. For package-specific behavior, inspect:

- `config/dompdf.php`
- `src/PDF.php`
- `src/ServiceProvider.php`
- `references/example.md`
- `references/package.md`

## Configuration

Laravel auto-discovers the service provider and facade aliases. Publish the config when the app needs local overrides:

```bash
php artisan vendor:publish --provider="Barryvdh\\DomPDF\\ServiceProvider"
```

## Basic Usage

Typical controller flow:

```php
use Barryvdh\DomPDF\Facade\Pdf;

return Pdf::loadView('pdf.invoice', [
    'order' => $order,
])->download('invoice.pdf');
```

Useful output methods:

- `download('file.pdf')` returns an attachment response
- `stream('file.pdf')` renders inline in the browser
- `save('path/file.pdf', $disk)` stores the generated PDF
- `output()` returns the raw PDF bytes for mail attachments or custom storage

## Examples

Use `resources/example.md` for copyable Laravel examples covering:

- Downloading a PDF from a Blade view
- Streaming a PDF inline in the browser
- Generating from an HTML string
- Saving to a path or Laravel filesystem disk
- Setting paper size, orientation, DPI, and default font
- Enabling PDF/A mode
- Enabling remote images with trusted hosts

## Working Pattern

1. Build a dedicated Blade view for the PDF.
2. Pass only the data the view needs.
3. Generate through `Pdf::loadView()` unless the source is already HTML or a file.
4. Set paper, orientation, and options explicitly when the document format matters.
5. Test the response headers or persisted file, not just the route status.

## Important Package Behavior

- `Pdf` and `PDF` facade aliases are both registered by the package.
- `loadView()` renders a Blade view and then passes the HTML to DOMPDF.
- The service provider binds `dompdf`, `dompdf.options`, and `dompdf.wrapper` into the container.
- `setOption()` and `setOptions()` write directly to DOMPDF options.
- `setWarnings(true)` makes render warnings throw exceptions.
- Since package 3.x, remote access is disabled by default. Enable it deliberately in `config/dompdf.php` when the PDF must load remote assets.
- Local file access is constrained by DOMPDF `chroot`; keep assets inside the allowed path.

## PDF/A And Embedded Files

For archival PDFs:

- Enable PDF/A in `config/dompdf.php` or call `setPdfA()`
- Use embedded fonts such as `DejaVu Sans` or `DejaVu Serif`
- Keep the backend on `CPDF`

For Factur-X / Zugferd style workflows, the package exposes:

- `setPdfA()`
- `setAdditionalXmpRdf()`
- `addEmbeddedFile()`

These methods require the `CPDF` backend.

## Blade And Asset Guidance

- Add `<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>` to PDF views that render non-ASCII text.
- Use print-friendly HTML and conservative CSS.
- Use page-break CSS when multi-page layout matters.
- Prefer absolute filesystem paths or confirmed reachable URLs for images and fonts.
- If fonts render incorrectly, check `font_dir`, `font_cache`, and whether the font can legally be embedded.

## Verification

For HTTP endpoints returning PDFs, verify:

- `Content-Type` is `application/pdf`
- `Content-Disposition` matches `download()` or `stream()`
- Generated bytes are non-empty

For saved PDFs, assert the file exists and compare its contents with `output()` when practical.

## Common Pitfalls

- Forgetting to publish or override `config/dompdf.php` when custom options are needed
- Expecting remote images to work while `isRemoteEnabled` is still disabled
- Using fonts that are not embedded for PDF/A validation
- Referencing files outside DOMPDF `chroot`
- Treating browser HTML and DOMPDF HTML/CSS support as identical

