Configs2026年7月26日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Dompdf Overview
直接安装命令
npx -y tokrepo@latest install 24476e91-8931-11f1-9bc6-00163e2b0d79 --target codex

先 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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产