OpenParable
Skip to content
← Back to skills

Laravel Dompdf

Documents
laravel-dompdf

Laravel Dompdf is an Agent Skill for documents published in the barryvdh/laravel-dompdf repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

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.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/barryvdh/laravel-dompdf/blob/HEAD/resources/boost/skills/laravel-dompdf/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/laravel-dompdf, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

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:

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

Basic Usage

Typical controller flow:

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