Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsJul 26, 2026·3 min de lectura

Dompdf — HTML to PDF Converter for PHP

A pure PHP library that renders HTML and CSS into PDF documents, widely used in Laravel and Symfony applications for generating invoices, reports, and printable content.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Dompdf Overview
Comando de instalación directa
npx -y tokrepo@latest install 24476e91-8931-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

Dompdf is an HTML-to-PDF conversion library written in pure PHP. It takes HTML markup and CSS stylesheets as input and produces a PDF file as output, making it straightforward to generate PDF documents from the same templates used for web pages. It is one of the most widely adopted PDF libraries in the PHP ecosystem.

What Dompdf Does

  • Converts HTML and CSS markup into PDF documents
  • Supports a wide subset of CSS 2.1 and some CSS 3 properties
  • Handles custom fonts via @font-face declarations
  • Generates table of contents, headers, footers, and page numbers
  • Produces PDF output as a downloadable stream, file, or string

Architecture Overview

Dompdf parses HTML into a DOM tree and CSS into a stylesheet object, then lays out the content using its own rendering engine that mimics browser layout behavior for the supported CSS subset. The laid-out content is drawn to a PDF canvas using either the bundled CPDF library or PDFLib if available. The entire process runs in PHP without external binaries.

Self-Hosting & Configuration

  • Install via Composer with composer require dompdf/dompdf
  • Configure options like paper size, orientation, and font directory via the Options class
  • Place custom fonts in the configured font directory and register them
  • Enable remote file access in options if your HTML references external images
  • Integrate with Laravel using the popular barryvdh/laravel-dompdf wrapper package

Key Features

  • Pure PHP implementation with no external binary dependencies
  • Supports @font-face for embedding custom TrueType and OpenType fonts
  • CSS page-break control for multi-page document layout
  • Built-in support for background images, gradients, and basic SVG
  • Configurable paper sizes from letter and A4 to custom dimensions

Comparison with Similar Tools

  • wkhtmltopdf — uses a WebKit engine for better CSS support but requires a system binary; Dompdf is pure PHP
  • mPDF — another pure PHP option with broader CSS support but larger memory footprint
  • TCPDF — lower-level PHP PDF library without HTML rendering; requires manual layout
  • Puppeteer/Playwright — headless browser approach with perfect rendering but heavier infrastructure needs

FAQ

Q: Does Dompdf support all CSS properties? A: No. It supports CSS 2.1 and select CSS 3 properties. Complex layouts with flexbox or grid are not supported.

Q: Can Dompdf handle large documents? A: It works for typical business documents. For very large documents (hundreds of pages), increase PHP memory limits or consider wkhtmltopdf.

Q: How do I use custom fonts? A: Place TrueType font files in the font directory and use @font-face in your CSS. Run the included font installation script to generate metrics.

Q: Is Dompdf suitable for production use? A: Yes. It is widely used in production for generating invoices, reports, and certificates in PHP applications.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados