承接 fawno/fpdf-traits 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fawno/fpdf-traits

Composer 安装命令:

composer require fawno/fpdf-traits

包简介

A modular plugin system for FPDF based on PHP Traits.

关键字:

README 文档

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

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-30