A modular plugin system for FPDF based on PHP Traits.
FPDF Traits is a collection of community FPDF scripts converted into reusable PHP Traits.
The original FPDF ecosystem provides many useful scripts (rotations, barcodes, tables, bookmarks, watermarks, etc.), but most of them rely on class inheritance, making it difficult to combine multiple scripts in the same PDF class.
This project solves that limitation by transforming those scripts into composable Traits.
Instead of:
class PDF extends PDF_Rotate
{
}you can now do:
class PDF extends FPDF
{
use RotateTrait;
use BookmarkTrait;
use Code128Trait;
}This allows developers to build custom PDF engines by composing only the features they need.
Traditional FPDF extensions have several limitations:
- Single inheritance restrictions
- Difficult script composition
- Tight coupling between scripts
- Repeated code between extensions
- Harder maintenance
Using Traits provides:
- Modular architecture
- Better code reuse
- Easier maintenance
- Multiple feature composition
- Cleaner integration
- Better compatibility with modern PHP projects
Install via Composer:
composer require fawno/fpdf-traits- PHP 8.1 or higher
- FPDF 1.8+
use Fawno\FPDF\FawnoFPDF;
$pdf = new FawnoFPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();use FPDF\Traits\Attachments\AttachmentsTrait;
class PDF extends FPDF {
use AttachmentsTrait;
}- PDFRotate by Olivier (2002-11-17)
- PDFTransform by Moritz Wagner & Andreas Würmser (2005-09-04)
- PDFDraw by David Hernández Sanz (2005-01-16)
- PDFBookmark by Olivier (2002-11-17)
- PDFMultiCellsTable by Olivier (2002-11-17)
- PDFCircularText by Andreas Würmserr (2006-04-09)
- RPDF by Pivkin Vladimir (2003-08-28)
- PDFCode128 by Roland Gautier (2016-01-31)
- QRcode by Laurent MINGUET (2010-04-29)
- PDFProtection by Klemen Vodopivec (2018-03-19)
- PDFMemImage by Olivier (2004-04-05)
- Attachments by Olivier (2012-04-29)
- ESignaturePlaceholder by Erik N. (2025-12-06)
Each Trait is a direct adaptation of an original FPDF script whenever possible.
The goal is to preserve compatibility with original examples and documentation.
This project is designed to work directly with the official FPDF class.
Some Traits may depend on internal FPDF methods like:
_out()_newobj()_putstream()
Because of this, compatibility may be tied to specific FPDF versions.
Please check each Trait documentation.
This project follows these principles:
- Keep original script behavior
- Minimal API changes
- Maximum composability
- Modern PHP standards
- Clean namespaces
- PSR-4 autoloading
Contributions are welcome.
You can help by:
- Porting new FPDF scripts into Traits
- Improving compatibility
- Writing tests
- Improving documentation
- Reporting issues
- Original FPDF library by Olivier Plathey
- Original community scripts from the FPDF Script Repository
- All contributors to the FPDF ecosystem