setasign/tfpdf
tFPDF is a lightweight PHP PDF generator based on FPDF with built-in TrueType/Unicode font support. Create PDFs with custom fonts, UTF-8 text, and simple drawing/layout features without external dependencies—ideal for invoices, reports, and basic document output.
composer require setasign/tfpdf. This package is a drop-in replacement for FPDF with UTF-8 support.\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')).Cell, MultiCell, SetXY)—UTF-8 only affects text encoding, not layout.SetFont(' DejaVu'...) for basic Latin + diacritics, and consider multicell for line-breaking text.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 for critical security updates if needed.Tfpdf and override Header(), Footer(), or add custom methods.How can I help you explore Laravel packages today?