fawno/fpdf-traits

A modular plugin system for FPDF based on PHP Traits.

Maintainers

Package info

github.com/fawno/FPDF-Traits

Homepage

pkg:composer/fawno/fpdf-traits

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.2 2026-06-30 16:38 UTC

This package is auto-updated.

Last update: 2026-06-30 16:38:33 UTC


README

GitHub Workflow GitHub license GitHub tag (latest SemVer) Packagist Packagist Downloads GitHub issues GitHub forks GitHub stars

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

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

Barcodes

  • PDFCode128 by Roland Gautier (2016-01-31)
  • QRcode by Laurent MINGUET (2010-04-29)

Others

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