setasign/tfpdf
tFPDF is a UTF-8 capable PDF generation library for PHP with TrueType font subset embedding. Composer package setasign/tfpdf provides the official tFPDF release with autoloader support and no namespace.
composer require setasign/tfpdf. This package is a drop-in replacement for FPDF with UTF-8 support.^1.34 (or at minimum >=1.34) — this patch fixes faulty CMAP generation, which affects text extraction/copy-paste from generated PDFs.\setasign\Tfpdf\Tfpdf instead of FPDF in your PDF-generating classes.$pdf = new \setasign\Tfpdf\Tfpdf();
$pdf->AddFont('DejaVu', '', 'DejaVuSans.ttf', true);
$pdf->AddPage();
$pdf->SetFont('DejaVu', '', 12);
$pdf->Write(0, 'Hello, 世界 🌍');
$pdf->Output();
examples/ directory in the repo and examples/font/ for TTF setup instructions.AddFont() with the 4th parameter set to true to register UTF-8-capable TrueType fonts. Fonts must reside in the fonts/ directory (usually vendor/setasign/tfpdf/fonts/ or custom path via setFontLocation()).Tfpdf::setFontLocation($path) before calling AddFont().Tfpdf instance (e.g., preloading DejaVu fonts).Output('pdf.pdf', 'F')).Storage::disk('local') and returns a signed URL; keeps the request cycle fast.Cell, MultiCell, SetXY)—UTF-8 only affects text encoding, not layout.SetFont('DejaVu'...) for basic Latin + diacritics, and consider MultiCell for line-breaking text.pdftotext in CI). This is the behaviour the CMAP fix targets, and it is the cheapest way to catch regressions in font/CMAP handling..php/.z artifacts written next to the .ttf) which embed the character map. After moving to 1.34, delete any previously generated definitions for your fonts and let them be rebuilt — otherwise you keep shipping PDFs with the old faulty CMAP even though the library is patched.AddFont() method expects fonts relative to the fonts/ directory unless setFontLocation() is called. Common error: font not found due to incorrect path—use absolute paths.output_buffering = Off and zlib.output_compression = Off in php.ini. Tfpdf may silently fail to output if headers have already been sent.Tfpdf::getError() after AddFont() or SetFont() to check for issues.require_once statements.LGPL) and consider forking or vendoring a pinned copy if you depend on security-sensitive behaviour.Tfpdf and override Header(), Footer(), or add custom methods.How can I help you explore Laravel packages today?