Skip to content

Migrate from DomPDF

This guide helps you migrate from DomPDF (dompdf/dompdf) to TCPDF-Next. The two libraries have fundamentally different design philosophies — DomPDF is an HTML/CSS-to-PDF renderer, while TCPDF-Next is a PDF-native library with a powerful HTML rendering engine.

DomPDF Approach vs TCPDF-Next Approach

DomPDF treats PDF generation as HTML rendering. You write HTML and CSS, and DomPDF converts it to a PDF. This is convenient but limits you to what CSS can express, with no access to native PDF features like digital signatures, encryption, or PDF/A compliance.

TCPDF-Next offers two approaches:

ApproachDescriptionBest For
Core APIDirect PDF construction via PHP methodsPrecision layouts, forms, graphics, signatures
Artisan HTML RendererDOM-based HTML/CSS renderer (HtmlRenderer)HTML-heavy content, migrating from DomPDF

For most DomPDF migrations, use the Artisan HTML Renderer — it accepts your existing HTML templates with minimal changes.

API Mapping

DomPDFTCPDF-NextNotes
new Dompdf($options)PdfDocument::create()->build()Fluent builder
$dompdf->loadHtml($html)$renderer->writeHtml($html)Same HTML works
$dompdf->loadHtmlFile($url)$renderer->writeHtmlFile($path)Local files only by default
$dompdf->setPaper('A4', 'portrait')->setPageFormat(PageFormat::A4)Enum-based
$dompdf->render()Automatic on save() / toString()No explicit render step
$dompdf->output()$pdf->toString()Returns binary string
$dompdf->stream('file.pdf')Framework response helpersSee examples below
$options->set('defaultFont', ...)$renderer->setDefaultFont(...)
$options->set('isRemoteEnabled', true)ResourcePolicy::allowDomain(...)Explicit allowlist
$options->set('chroot', $dir)ResourcePolicy::allowLocalDirectory(...)More granular control

Basic Migration Example

DomPDF (before):

php
use Dompdf\Dompdf;
use Dompdf\Options;

$options = new Options();
$options->set('defaultFont', 'Helvetica');
$options->set('isRemoteEnabled', true);

$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
file_put_contents('output.pdf', $dompdf->output());

TCPDF-Next (after):

php
use YeeeFang\TcpdfNext\Document\PdfDocument;
use YeeeFang\TcpdfNext\Document\PageFormat;
use YeeeFang\TcpdfNext\Html\HtmlRenderer;

$pdf = PdfDocument::create()
    ->setPageFormat(PageFormat::A4)
    ->build();

$renderer = new HtmlRenderer($pdf);
$renderer->setDefaultFont('Helvetica', size: 12);
$renderer->writeHtml($html);

$pdf->save('output.pdf');

CSS Support Comparison

CSS FeatureDomPDFTCPDF-Next
Box model (margin, padding, border)YesYes
FloatsPartialPartial
FlexboxNoNo
GridNoNo
position: absolute/relativePartialYes
@font-faceYesYes
page-break-before/afterYesYes
background-imagePartialYes
border-radiusNoYes
opacityYesYes
CSS variables (--custom)NoNo
Media queriesNo@media print only
table layoutYesYes (improved)

TIP

TCPDF-Next's HTML renderer supports most CSS 2.1 properties and selected CSS 3 properties. Flexbox and Grid are not supported — use tables for complex layouts. If you encounter CSS rendering differences, check the HTML Renderer documentation.

When to Use Core vs Artisan

ScenarioRecommended Approach
Migrating existing HTML templatesArtisan HTML Renderer
Pixel-perfect layouts (invoices, certificates)Core API
Digital signatures requiredCore API (signing works with both, but Core gives more control)
PDF/A complianceEither (both support PDF/A-4)
Barcodes / QR codesCore API (native vector rendering)
Forms with fillable fieldsCore API
Simple reports from HTMLArtisan HTML Renderer

Performance Comparison

MetricDomPDFTCPDF-NextImprovement
Simple 1-page PDF62.1 ms8.2 ms7.6x faster
20-page report891 ms187 ms4.8x faster
Peak memory (1 page)22.1 MB4.2 MB5.3x less
Peak memory (20 pages)89.7 MB12.4 MB7.2x less
Output file size (1 page)31.8 KB12.4 KB2.6x smaller

See Performance Benchmarks for detailed methodology and additional test cases.

New Capabilities After Migration

Features available in TCPDF-Next that DomPDF does not support:

  • Digital signatures — PAdES B-B through B-LTA with hardware security module support.
  • AES-256 encryption — Password and certificate-based document protection.
  • PDF/A-4 — Full archival compliance (ISO 19005-4).
  • Tagged PDF / PDF/UA — Accessibility for screen readers.
  • Native barcodes — QR, Data Matrix, Code 128, EAN, and more as vector graphics.
  • Form fields — Fillable text fields, checkboxes, dropdowns.
  • Cross-reference streams — Smaller file sizes with modern PDF structure.

Further Reading

Released under the LGPL-3.0-or-later License.