fawno/fpdf-traits
Composer 安装命令:
composer require fawno/fpdf-traits
包简介
A modular plugin system for FPDF based on PHP Traits.
README 文档
README
FPDF Traits
A modular plugin system for FPDF based on PHP Traits.
What is this?
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.
Why?
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
Installation
Install via Composer:
composer require fawno/fpdf-traits
Requirements
- PHP 8.1 or higher
- FPDF 1.8+
Basic usage
use Fawno\FPDF\FawnoFPDF; $pdf = new FawnoFPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output();
Alternative usage
use FPDF\Traits\Attachments\AttachmentsTrait; class PDF extends FPDF { use AttachmentsTrait; }
Available Traits
Graphics
- 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)
Text
- 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)
Barcodes
- PDFCode128 by Roland Gautier (2016-01-31)
- QRcode by Laurent MINGUET (2010-04-29)
Others
- 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)
Compatibility
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.
Philosophy
This project follows these principles:
- Keep original script behavior
- Minimal API changes
- Maximum composability
- Modern PHP standards
- Clean namespaces
- PSR-4 autoloading
Contributing
Contributions are welcome.
You can help by:
- Porting new FPDF scripts into Traits
- Improving compatibility
- Writing tests
- Improving documentation
- Reporting issues
Credits
- Original FPDF library by Olivier Plathey
- Original community scripts from the FPDF Script Repository
- All contributors to the FPDF ecosystem
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-30