mPDF is a PHP package that turns UTF-8 HTML into PDF files. You install it via Composer and call it from your PHP application.
Overview
mPDF generates PDF documents from UTF-8 encoded HTML. It extends ideas from FPDF and HTML2FPDF with added layout and language support, including CJK text when the right extensions are available.
You integrate it as a PHP dependency, construct a document object with optional configuration, write HTML, and output PDF bytes to the browser or a file. Configuration covers temp directories, fonts, and many layout directives passed through the constructor.
The project documents CSS support as dated compared with newer non-PHP tools; templates are often tuned specifically for mPDF. It supports features such as color handling, barcodes, headers and footers, page numbers, and tables of contents relative to simpler HTML-to-PDF approaches.
Running under nginx with php-fpm or Apache is recommended instead of PHP's built-in single-threaded development server when fetching external HTTP resources. User-supplied HTML should be validated above the library, as mPDF is not meant to accept untrusted markup from end users.
Key features
- HTML and CSS to PDF conversion
- UTF-8 and CJK text support
- Headers, footers, and page numbers
- Barcode generation
- Table of contents support
- Configurable temp and font paths
- Composer package distribution
- Inline browser PDF output
Use cases
- Server-side invoice or report PDFs
- Multilingual PDF from HTML templates
- On-the-fly PDF in PHP web apps
- Print-oriented layouts from CMS content
- Documents needing barcodes or TOCs