Migrate from mPDF
This guide helps you migrate from mPDF (mpdf/mpdf) to TCPDF-Next. mPDF is an HTML-to-PDF library with broad CSS support and features like CJK text, barcodes, and watermarks. TCPDF-Next offers a superset of mPDF's capabilities with modern standards compliance and zero runtime dependencies.
Feature Comparison
| Feature | mPDF | TCPDF-Next |
|---|---|---|
| PHP version | 7.4+ | 8.5+ |
| PDF version | PDF 1.4 / 1.7 | PDF 2.0 |
| Architecture | HTML/CSS-centric | PDF-native with HTML support |
| Runtime dependencies | 10+ Composer packages | Zero |
| Encryption | RC4, AES-128, AES-256 | AES-256 only (PDF 2.0) |
| Digital signatures | Not supported | PAdES B-B through B-LTA |
| PDF/A | PDF/A-1b, PDF/A-3b (partial) | PDF/A-4 (full ISO 19005-4) |
| Tagged PDF | Limited | Full PDF/UA accessibility |
| CJK support | Yes (bundled 50+ MB fonts) | Yes (register your own, optimized subsetting) |
| RTL / BiDi | Yes | Yes (UAX #9 compliant) |
| Barcodes | Yes (1D and 2D) | Yes (native vector, expanded set) |
| Watermarks | Yes | Yes |
| TOC generation | Yes | Yes |
| Memory usage | High (full DOM in memory) | Moderate (streaming output) |
mPDF-Specific Features and TCPDF-Next Equivalents
Custom HTML Tags
mPDF defines non-standard HTML tags. These require adaptation:
| mPDF Custom Tag | TCPDF-Next Equivalent |
|---|---|
<tocpagebreak> | $pdf->addTableOfContentsPage() |
<tocentry content="..." level="0"> | $toc->addEntry('...', level: 0) |
<barcode code="..." type="C128"> | $page->addBarcode(BarcodeFactory::code128('...')) |
<columnbreak> | $renderer->columnBreak() |
<pagebreak> | <div style="page-break-before: always"> (standard CSS) |
<bookmark content="..."> | $pdf->addBookmark('...') |
<watermarktext content="DRAFT"> | $pdf->setWatermark(Watermark::text('DRAFT')) |
<watermarkimage src="..."> | $pdf->setWatermark(Watermark::image('...')) |
HTML Headers and Footers
mPDF (before):
php
$mpdf->SetHTMLHeader('<div style="text-align: center;">Header</div>');
$mpdf->SetHTMLFooter('<div>Page {PAGENO} of {nbpg}</div>');
$mpdf->SetHTMLHeader('<div>Even header</div>', 'E');TCPDF-Next (after):
php
$pdf->setHtmlHeader('<div style="text-align: center;">Header</div>');
$pdf->setHtmlFooter('<div>Page {{pageNumber}} of {{totalPages}}</div>');
$pdf->setHtmlHeader('<div>Even header</div>', pages: 'even');WriteHTML Modes
mPDF (before):
php
$mpdf->WriteHTML($css, \Mpdf\HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($body, \Mpdf\HTMLParserMode::HTML_BODY);TCPDF-Next (after):
php
$renderer = new HtmlRenderer($pdf);
$renderer->addStylesheet($css);
$renderer->writeHtml($body);Watermarks
mPDF (before):
php
$mpdf->SetWatermarkText('DRAFT', 0.1);
$mpdf->showWatermarkText = true;TCPDF-Next (after):
php
$pdf->setWatermark(
Watermark::text('DRAFT')
->setOpacity(0.1)
->setRotation(45)
->setColor(Color::rgb(200, 200, 200))
);Configuration Mapping
| mPDF Config | TCPDF-Next Equivalent |
|---|---|
mode => 'utf-8' | Always UTF-8 (no config needed) |
format => 'A4' | setPageFormat(PageFormat::A4) |
margin_left/right/top/bottom | setMargins(new Margins(...)) |
default_font | $renderer->setDefaultFont(...) |
tempDir | PdfDocument::create()->setTempDir(...) |
autoScriptToLang | $renderer->setAutoFontDetection(true) |
biDirectional | Always enabled (UAX #9) |
pdfaAuto | setPdfALevel(PdfALevel::PDF_A_4) |
Output Methods
mPDF (before):
php
$mpdf->Output('/path/to/file.pdf', \Mpdf\Output\Destination::FILE);
$mpdf->Output('doc.pdf', \Mpdf\Output\Destination::DOWNLOAD);
$mpdf->Output('doc.pdf', \Mpdf\Output\Destination::INLINE);
$content = $mpdf->Output('', \Mpdf\Output\Destination::STRING_RETURN);TCPDF-Next (after):
php
$pdf->save('/path/to/file.pdf');
$bytes = $pdf->toString();
// Web response (Laravel example)
return response($pdf->toString(), 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="doc.pdf"',
]);Dependency Reduction
Migrating from mPDF dramatically simplifies your dependency tree:
Removed (mPDF + transitive):
mpdf/mpdf+ 10+ transitive packagespsr/log,psr/http-message,setasign/fpdi,mpdf/qrcode
Added:
yeee-fang/tcpdf-next(zero runtime dependencies)
Performance Comparison
| Metric | mPDF | TCPDF-Next | Improvement |
|---|---|---|---|
| Simple 1-page PDF | 45.3 ms | 8.2 ms | 5.5x faster |
| 100-page document | 3,210 ms | 845 ms | 3.8x faster |
| Peak memory (1 page) | 18.4 MB | 4.2 MB | 4.4x less |
| Peak memory (100 pages) | 198.2 MB | 28.6 MB | 6.9x less |
| Output file size (1 page) | 24.3 KB | 12.4 KB | 2.0x smaller |
See Performance Benchmarks for full methodology and test cases.
Further Reading
- API Mapping Table — Comprehensive method mapping
- Benchmarks — Full performance comparison with mPDF
- API Reference — Full TCPDF-Next API documentation
- FAQ — Common migration questions