Documentation page: PD4ML for PHP Compared with mPDF, Dompdf and TCPDF. This page is also available as Markdown at php-html-to-pdf-library-comparison.md.

PD4ML for PHP Compared with mPDF, Dompdf and TCPDF

PHP developers who need HTML to PDF usually start with one of three open-source libraries: mPDF, Dompdf or TCPDF. They install with Composer, run in pure PHP and cost nothing, and for simple invoices and reports they work well. This page compares them with PD4ML for PHP, the Composer package that brings the PD4ML layout engine to PHP, so you can see where each one fits: modern CSS layout, PDF/A and PDF/UA, e-invoices, Word output, signatures, deployment and license.

The comparison covers PD4ML v4.1.1 and, marked 4.2, features of the upcoming PD4ML 4.2 with its new v42 layout engine, which the PHP module uses by default. TCPDF is listed together with its successor, tc-lib-pdf, because its author has moved TCPDF to maintenance mode. Information about the other libraries comes from their documentation and Packagist pages as of November 2026; a cell marked "not verified" means we could not confirm it from public sources.

At a glance

  • PD4ML for PHP (pd4ml/pd4ml-php) runs the PD4ML engine in a small Java process and exposes its full API to PHP. It needs PHP 8.1 and Java 8 or later. Commercial license, perpetual, from €100; free evaluation with a watermark.
  • mPDF (mpdf/mpdf, 8.3) is a pure-PHP library generating PDF from UTF-8 HTML, strong in right-to-left and complex scripts. GPL-2.0.
  • Dompdf (dompdf/dompdf, 3.1) is a pure-PHP, CSS 2.1 HTML renderer with some CSS3. LGPL-2.1.
  • TCPDF (tecnickcom/tcpdf) is a long-standing PHP PDF library with a limited HTML subset, now in maintenance mode. Its successor tc-lib-pdf (8.x, LGPL-3.0) adds a CSS cascade, PDF/A, PDF/UA and signatures.

Requirements, installation and license

Item PD4ML mPDF Dompdf TCPDF / tc-lib-pdf
Composer package pd4ml/pd4ml-php mpdf/mpdf dompdf/dompdf tecnickcom/tcpdf, tecnickcom/tc-lib-pdf
PHP version 8.1 or later 5.6 to 8.5 7.1 or later tc-lib-pdf: 8.2 or later
Runtime PHP plus Java 8 or later Pure PHP; gd, mbstring Pure PHP; dom, mbstring, GD for images Pure PHP
Works on shared hosting without Java Not supported Supported Supported Supported
Web server setup One bridge server for PHP-FPM or mod_php (vendor/bin/pd4ml serve) None None None
License Commercial, perpetual GPL-2.0 LGPL-2.1 TCPDF: LGPL-3.0; tc-lib-pdf: LGPL-3.0 or later
Price €100 single, €1,600–3,200 site, €8,000–16,000 enterprise (one-time) Free Free Free
Closed-source commercial use Supported Under the license Partial or add-on GPL obligations apply when you distribute Supported Supported
Commercial support Supported Not supported Community Not supported Community Not supported Community

The GPL matters if you ship software to customers: distributing an application linked with mPDF can oblige you to release it under the GPL. For a hosted web application that you do not distribute, it usually does not. Check with your legal adviser.

Install PD4ML with:

composer require pd4ml/pd4ml-php
vendor/bin/pd4ml install

Details: PD4ML for PHP.

HTML and CSS layout support

Feature PD4ML mPDF Dompdf TCPDF / tc-lib-pdf
CSS level Modern CSS; v42 engine checked against Chrome 4.2 CSS 2 subset with some CSS3 Most of CSS 2.1, a few CSS3 properties TCPDF: limited HTML subset; tc-lib-pdf: CSS cascade and @media
Flexbox Supported Not supported Not supported Not verified
CSS Grid Supported Template areas, line names, dense placement 4.2 Not supported Not supported Not verified
Floats Supported Partial or add-on Partial; no nested floats Partial or add-on Partial or add-on
Absolute and fixed positioning Supported Partial or add-on Top-level elements only Supported Partial or add-on
CSS @page Supported Size, :first/:left/:right, named pages, margin boxes 4.2 Supported Named pages, own header and footer tags Supported Not verified
Headers, footers, page numbers Supported HTML headers and footers with page and total counts Supported Partial or add-on Through @page and page scripts Supported Through the API
Table rows split across pages Supported Supported Not supported A row must fit on one page Partial or add-on
Repeated table headers Supported Supported Supported Supported
Media queries Supported Level 4 range syntax 4.2 Partial or add-on Supported Supported tc-lib-pdf
Vector SVG Supported Supported Supported Supported
MathML Supported Not supported Not supported Not supported
Barcodes and QR codes Supported QR codes (<qrcode>) Supported Not supported Supported
JavaScript Not supported Not supported Not supported Not supported

PD4ML's @page support is described in CSS @page rules, and its DOM API (Java, DMS and UA editions) in modifying the HTML document before conversion.

Dompdf documents that it does not support Flexbox or CSS Grid, and mPDF's supported CSS list does not include them either. Templates built with a modern CSS framework usually have to be rewritten with tables for those two.

Output formats

Format PD4ML mPDF Dompdf TCPDF / tc-lib-pdf
PDF Supported Supported Supported Supported
DOCX (Word) Supported Not supported Not supported Not supported
RTF Supported Not supported Not supported Not supported
PNG and TIFF images Supported Not supported Not supported Not supported
Several formats from one parse Supported Not supported Not supported Not supported

PDF/A, PDF/UA and e-invoices

Standard PD4ML mPDF Dompdf TCPDF / tc-lib-pdf
PDF/A Supported PDF/A-1a/1b, 2a/2b/2u, 3a/3b/3u, 4, 4e Supported PDF/A-1b and PDF/A-3b Partial or add-on Experimental PDF/A-3b mode; fonts must be embedded by you Supported tc-lib-pdf: PDF/A-1, 2, 3 (a, b, u)
PDF/UA accessible PDF Supported PDF/UA-1 and PDF/UA-2 Not supported Not supported Supported tc-lib-pdf: PDF/UA-1 and PDF/UA-2
ZUGFeRD and Factur-X Supported Presets, including accessible PDF/A-3a invoices Partial or add-on PDF/A-3 associated files, built by hand Not supported Supported tc-lib-pdf: setFacturX()
PDF/X for print Not supported Supported PDF/X-1a Not supported Supported tc-lib-pdf: PDF/X-1a to X-5
PDF 2.0 Supported Not supported Not supported Not verified

See PDF/A, PDF/UA and e-invoicing formats and ZUGFeRD and Factur-X PDF invoices.

Fonts and international text

Feature PD4ML mPDF Dompdf TCPDF / tc-lib-pdf
TrueType and OpenType embedding with subsetting Supported Supported Supported Through @font-face; built-in fonts are Windows ANSI only Supported
Unicode by default Supported Supported Partial or add-on DejaVu fonts preinstalled Supported
Arabic and Hebrew, right to left Supported Supported Not verified Supported
Indic scripts Supported Supported Not verified Not verified
Kerning and ligatures Supported Supported OpenType layout features Not verified Not verified
WOFF2 web fonts Supported Not verified Not verified Not verified

mPDF is traditionally the strongest of the three open-source libraries for right-to-left and complex scripts.

Security, signatures and forms

Feature PD4ML mPDF Dompdf TCPDF / tc-lib-pdf
Passwords and permissions Supported RC4, AES-128/256 Supported Supported Supported Up to AES-256
Digital signatures Supported PKCS#12, PKCS#11, HSM, cloud KMS, RFC 3161, PAdES-LT/LTV Not supported Not supported Supported tc-lib-pdf: PAdES B-B to B-LTA
Fillable forms from HTML Supported Inputs, selects, text areas, buttons Partial or add-on Not supported Supported Through the API
Merge, optimize, XFDF Supported Partial or add-on Import pages of other PDFs Not supported Not verified

When to choose which

  • Dompdf suits simple invoices and letters with table layouts, when you want a permissive license and the least setup.
  • mPDF suits documents in Arabic, Hebrew or Indic scripts with traditional layout, and PDF/A-1b or PDF/A-3b archives, if the GPL fits your distribution model.
  • TCPDF suits existing code that builds PDFs through its API. For new projects, its author recommends tc-lib-pdf, which adds PDF/A, PDF/UA, PDF/X and signatures.
  • PD4ML for PHP suits templates written with modern CSS (Flexbox, Grid, @page), documents that also need DOCX or RTF, accessible PDF/UA and e-invoices from HTML, and teams that want commercial support. It needs Java on the server, so it is not an option on shared hosting without Java.

Frequently asked questions

What is the best PHP library for converting HTML to PDF?

For simple layouts without modern CSS, Dompdf and mPDF are free and need nothing but PHP. If your HTML uses Flexbox or CSS Grid, or you need PDF/UA, ZUGFeRD or Word output, PD4ML for PHP covers that through Composer, with Java on the server.

Does Dompdf or mPDF support Flexbox and CSS Grid?

No. Dompdf documents that it supports neither, and mPDF's list of supported CSS includes neither. PD4ML supports both, and PD4ML 4.2 implements CSS Grid to the specification.

Is PD4ML a good alternative to mPDF?

Yes, when you need modern CSS layout, PDF/UA, PDF/A-2 or PDF/A-4, digital signatures, or DOCX and RTF output, or when the GPL does not fit your product. mPDF remains simpler to deploy because it needs no Java.

Do I need Java to use PD4ML in PHP?

Yes. PD4ML for PHP runs the PD4ML engine in a Java 8 or later process. On web servers you run one bridge server (vendor/bin/pd4ml serve) that all PHP requests share; Java starts once, and each conversion then takes milliseconds for an ordinary document.

Can PHP create PDF/A and ZUGFeRD invoices from HTML?

Yes. PD4ML has presets for ZUGFeRD and Factur-X on PDF/A-3, including accessible PDF/A-3a invoices. mPDF can produce PDF/A-3b with associated files assembled by hand, and tc-lib-pdf offers a Factur-X workflow through its API.

Can PHP convert HTML to Word (DOCX)?

Among these libraries, only PD4ML converts HTML and CSS to DOCX and RTF, from the same layout as the PDF.

Is TCPDF still maintained?

TCPDF is in maintenance mode. Its author recommends tc-lib-pdf for new projects; TCPDF 7 is a compatibility layer on top of it.

Try PD4ML for PHP

Install the module with Composer, run vendor/bin/pd4ml install, and convert one of your own templates. Unlicensed output carries a watermark, with all features enabled. See PD4ML for PHP, the comparison with Java HTML-to-PDF libraries, and PD4ML editions and prices.

Product names are trademarks of their respective owners. Information about other libraries is taken from their public documentation as of November 2026 and may have changed; corrections are welcome through PD4ML support. This page is not legal advice on open-source licenses.