tecnickcom/tcpdf
TCPDF is a mature PHP library for generating PDF documents without external dependencies. Create pages, headers/footers, tables, images, barcodes, and multilingual/RTL text, with fine control over fonts, layout, and output (inline, download, file).
Start by installing via Composer: composer require tecnickcom/tcpdf. The library is PSR-4 compliant and located under TCPDF namespace. For immediate use, instantiate TCPDF, set basic meta (title, author), add a page, then output with Output() or Inline(). A minimal example:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Your Name');
$pdf->SetTitle('My PDF');
$pdf->AddPage();
$pdf->Write(0, 'Hello, PDF!');
$pdf->Output('example.pdf', 'I'); // inline browser view
Check the examples/ directory in the package for quick-reference snippets (HTML content, barcodes, headers/footers).
writeHTML() to render styled content (though CSS support is limited — prefer inline styles and basic tags).write2DBarcode() for QR, Code128, etc., with full control over positioning and size.TCPDF and override Header()/Footer() for consistent document branding.startTransaction()/rollbackTransaction() to revert content on errors (e.g., failed validation mid-document).addTTFfont() for advanced typography (ensure font is embedded for portability).PdfService that wraps TCPDF, injecting config (margins, fonts) via environment. Use facades or dependency injection to manage lifecycle.__construct() Parameters: The library uses legacy-style setters instead of DI — avoid passing config to the constructor beyond core flags.ob_get_clean() before output and increase memory_limit in production.<table> layouts and inline style="width:50mm" for predictability.'D' (download) for file downloads and 'I' for browser preview; 'F' saves to disk (useful in background jobs).setRTL(false) and setPrintHeader(false)/setPrintFooter(false) when troubleshooting layout drift.addTTFfont() silently fails if fonts aren’t publicly accessible — validate font paths and use absolute paths.htmlspecialchars() before writeHTML() to prevent XSS.How can I help you explore Laravel packages today?