Dompdf
Convert styled HTML and CSS into downloadable PDF documents in PHP.
Repository Health
Technical Analysis
Dompdf is a CSS 2.1-compliant HTML-to-PDF converter written in PHP. It reads an HTML document, applies the associated CSS (including many CSS 2.1 features and some CSS3), lays out the content, and renders it to a PDF you can stream to the browser or save to disk. This lets teams generate invoices, reports, tickets, and certificates from ordinary web markup rather than a proprietary PDF API.
Internally it is a full rendering engine: an HTML5 parser builds a DOM, a CSS cascade resolves styles, a frame tree performs box-model layout, and a renderer draws to a PDF canvas with support for embedded fonts, raster images, and SVG. Because it works from HTML and CSS, designers can iterate on document layouts using familiar web tools.
What You Get
- A CSS 2.1-compliant HTML-to-PDF rendering engine in pure PHP
- Support for embedded and web fonts, raster images, and inline SVG
- A simple loadHtml() -> render() -> output()/stream() workflow
- Configurable Options for paper size, orientation, remote assets, and DPI
- PDF backends including the bundled CPDF renderer
Common Use Cases
- Generating invoices, receipts, and order confirmations as PDFs
- Producing printable reports and statements from web dashboards
- Creating tickets, certificates, and badges from HTML templates
- Exporting styled content to a downloadable, print-ready document
Under The Hood
Architecture - Dompdf is a staged rendering pipeline orchestrated by src/Dompdf.php. HTML is parsed into a DOM (via masterminds/html5), the CSS engine in src/Css builds and cascades a stylesheet, and a frame tree (src/Frame, FrameDecorator, FrameReflower, Positioner) implements CSS box-model layout by reflowing and positioning boxes. A Renderer walks the laid-out frames and draws to a Canvas adapter (default CPDF), with FontMetrics, the Image subsystem, and a JavascriptEmbedder handling fonts, images, and inline PDF scripting.
Tech Stack - PHP 7.1+/8.x requiring ext-dom and ext-mbstring, with masterminds/html5 for parsing, dompdf/php-font-lib for font handling, and dompdf/php-svg-lib for SVG. Development uses PHPUnit, PHP_CodeSniffer, and Mockery.
Code Quality - The codebase is large but cleanly decomposed by rendering stage (Css, Frame, FrameReflower, Positioner, Renderer, Adapter), with a substantial tests/ suite and active community maintenance reflected in its high repo-health score. The complexity is inherent to implementing a CSS layout engine rather than accidental.
API Design - Despite the engine’s internal depth, the public API is small and approachable: instantiate Dompdf, call loadHtml(), optionally setPaper(), then render() and stream()/output(). Configuration is centralized in an Options object, so common documents take only a handful of lines while advanced control remains available.