PHPackages                             jdz/pdfbuilder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. jdz/pdfbuilder

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

jdz/pdfbuilder
==============

Build a PDF with TCPDF and FPDI

1.0.1(4mo ago)05↓75%MITPHPPHP &gt;=8.2

Since Apr 9Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/joffreydemetz/pdfBuilder)[ Packagist](https://packagist.org/packages/jdz/pdfbuilder)[ Docs](https://jdz.joffreydemetz.com/pdfbuilder)[ RSS](/packages/jdz-pdfbuilder/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

jdz/pdfbuilder
==============

[](#jdzpdfbuilder)

PHP library for building structured PDFs using TCPDF and FPDI.

Provides a **Builder/Modelizer** pattern for generating multi-page PDFs with YAML-driven configuration, automatic config inheritance, color/font management, and unit conversion utilities.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- [TCPDF](https://github.com/tecnickcom/TCPDF) ^6.3
- [FPDI](https://www.setasign.com/products/fpdi/about/) ^2.6
- [Symfony YAML](https://symfony.com/doc/current/components/yaml.html) ^7.2

Installation
------------

[](#installation)

```
composer require jdz/pdfbuilder
```

### PDF 1.5+ support (optional)

[](#pdf-15-support-optional)

FPDI natively handles PDF documents up to version 1.4. To import PDF 1.5+ files (those using compressed cross-references and object streams), you need the commercial [FPDI PDF-Parser](https://www.setasign.com/products/fpdi-pdf-parser/details/) add-on from Setasign.

1. Purchase a license at [setasign.com](https://www.setasign.com/products/fpdi-pdf-parser/details/)
2. Add the Setasign private Composer repository to your project's `composer.json`:

```
{
    "repositories": [
        {
            "type": "composer",
            "url": "https://www.setasign.com/downloads/"
        }
    ]
}
```

3. Require the package (you will be prompted for your Setasign credentials):

```
composer require setasign/fpdi_pdf-parser
```

Once installed, FPDI automatically detects the parser and enables PDF 1.5+ support — no code changes needed.

Architecture
------------

[](#architecture)

### Core classes

[](#core-classes)

ClassRole`Builder`Abstract base class. Loads YAML modelizer configs with inheritance, registers fonts, orchestrates PDF generation. Concrete builders extend this and implement `build()`.`Modelizer`Base class for rendering a single page type. Subclasses override `Page()`, `Header()`, and `Footer()` to define layout. Handles margins, page breaks, and page number placeholders.`Data`Configuration container extending `jData`. Manages colors (`Color`), fonts (`Font`), and provides unit conversion methods (`px2mm`, `px2pt`, `mm2px`, `percent2mm`).`Pdf`FPDI/TCPDF bridge. Wraps `setasign\Fpdi\Tcpdf\Fpdi` with custom font loading, model-based Header/Footer callbacks, and page number offset support.`Helper`Utility class for unit conversions, image sizing/resolution, border definition, and TOC export.### Built-in modelizers

[](#built-in-modelizers)

ModelizerPurpose`ImageModelizer`Renders a full-page image scaled to page width.`PdfModelizer`Includes pages from an existing PDF file via FPDI.`FormAbstractModelizer`Provides form building helpers: text fields, checkboxes, radio buttons, signatures.### Supporting classes

[](#supporting-classes)

ClassPurpose`Color`RGB/Hex color with HSV conversion, `lighten()` and `darken()` methods.`Font`Font name, size, and style holder.`Book`Container for `Toc` and `BookText` in multi-page documents.`BookText`Multilingual text management (fr, en, it) with plural support.`Toc`Table of Contents with page mark tracking.Configuration
-------------

[](#configuration)

Modelizer configs are YAML files stored in a `config/` directory. They support inheritance via the `inherits` key.

**Example:** `modelizer.formation.yml`

```
inherits:
  - base
  - catalogue

colors:
  pictoNewColor: "#cc0000"
  pictoCpfColor: "#01a6ba"

marginTop: 120
marginBottom: 62
pagePadding: 18
```

The `base` config provides defaults for all colors, fonts, and font sizes:

```
colors:
    white: "#FFFFFF"
    black: "#000000"
    textColor: "#000000"
    linkColor: "#0b8181"

fonts:
    default: helvetica
    black: helvetica
    light: helvetica

h1Fsize: 17
h2Fsize: 16
pFsize: 9
borderWidth: 0.1
```

Configs are loaded via `Builder::loadModelizerConfig('formation')`, which resolves the full inheritance chain and merges colors, fonts, and all other properties.

Usage
-----

[](#usage)

### 1. Create a Modelizer (page layout)

[](#1-create-a-modelizer-page-layout)

```
use JDZ\Pdf\Modelizer;

class InvoiceModelizer extends Modelizer
{
    protected bool $printHeader = true;
    protected bool $printFooter = true;

    public function Header(): void
    {
        $this->pdf->SetFont('helvetica', 'B', 14);
        $this->pdf->Cell(0, 10, 'INVOICE', 0, 1, 'C');
    }

    public function Page(): void
    {
        $invoice = $this->data->get('invoice');

        $this->pdf->SetFont('helvetica', '', 10);
        $this->pdf->Cell(0, 8, 'Client: ' . $invoice->client, 0, 1);
        $this->pdf->Cell(0, 8, 'Amount: ' . $invoice->amount, 0, 1);
    }

    public function Footer(): void
    {
        $this->pdf->SetY(-15);
        $this->pdf->SetFont('helvetica', '', 8);
        $this->pdf->Cell(0, 10, 'Page ' . $this->pdf->getAliasNumPage(), 0, 0, 'C');
    }
}
```

### 2. Create a Builder

[](#2-create-a-builder)

```
use JDZ\Pdf\Builder;
use JDZ\Pdf\Pdf;
use JDZ\Pdf\Data;

class InvoiceBuilder extends Builder
{
    private object $invoiceData;

    public function setInvoiceData(object $data): void
    {
        $this->invoiceData = $data;
    }

    public function build(): void
    {
        $pdf = new Pdf();
        $pdf->SetTitle('Invoice');
        $pdf->set('izSourcesPath', $this->sourcesPath);

        // Load YAML config with inheritance
        $modelizerData = new Data();
        $modelizerData->sets($this->loadModelizerConfig('invoice'));
        $modelizerData->set('invoice', $this->invoiceData);

        // Create modelizer, render page
        $modelizer = new InvoiceModelizer($pdf, $modelizerData);
        $modelizer->load();
        $modelizer->toPdf();

        // Write PDF to disk
        $pdf->Output($this->targetPath, 'F');
    }
}
```

### 3. Generate the PDF

[](#3-generate-the-pdf)

```
use JDZ\Utils\Data as jData;

$data = new jData();
$data->set('label', 'Invoice #001');

$builder = new InvoiceBuilder(
    sourcesPath: __DIR__ . '/resources/',
    targetPath: __DIR__ . '/files/invoice.pdf',
    data: $data
);

$builder->setInvoiceData((object)[
    'client' => 'Acme Corp',
    'amount' => '1 500,00 EUR',
]);

$builder->build();
```

Custom fonts
------------

[](#custom-fonts)

Register fonts in your Builder's `build()` method before creating the Modelizer:

```
$pdf->set('font', (object)[
    'name' => 'montserrat',
    'styles' => [null, 'B', 'I', 'BI'],
]);
```

Font definition files (PHP arrays) go in your `resources/fonts/` directory. The library ships with Helvetica, Courier, Montserrat, and Merienda.

Color manipulation
------------------

[](#color-manipulation)

```
// Get a color clone and lighten it
$color = $data->getColorObject('theme');
$color->lighten(20);
$lightTheme = $color->toArray(); // [r, g, b]
```

The `Color` class supports hex-to-RGB conversion, HSV transformations, and `lighten()`/`darken()` methods.

Examples
--------

[](#examples)

The `examples/` directory contains complete working examples:

ExampleDescriptionOutput`cv.php`CV / ResumeSingle-page CV with photo, skills, experience`offre.php`Job offerJob posting with company info and description`formation.php`Training courseCourse sheet with programme, sessions, side panel`catalogue.php`Multi-page catalogueCover page + category separators + 10 course sheets`invoice.php`InvoiceProfessional invoice with items table and totals`booktoc.php`Book with TOCCover + table of contents + 5 chapters with clickable linksRun an example:

```
php examples/cv.php
# Output: examples/files/cv-1.pdf
```

License
-------

[](#license)

MIT - See [LICENSE](LICENSE) for details.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance74

Regular maintenance activity

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

143d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e83e3701566e43438525ed14578487e732b849d152b5071aa1613a0dad96913?d=identicon)[jdz](/maintainers/jdz)

---

Top Contributors

[![joffreydemetz](https://avatars.githubusercontent.com/u/15113527?v=4)](https://github.com/joffreydemetz "joffreydemetz (8 commits)")

---

Tags

pdfservicesutilitiesJDZ

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jdz-pdfbuilder/health.svg)

```
[![Health](https://phpackages.com/badges/jdz-pdfbuilder/health.svg)](https://phpackages.com/packages/jdz-pdfbuilder)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

605.9M716](/packages/shopware-core)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.8k40.0k](/packages/matomo-matomo)[horstoeko/zugferd

A library for creating and reading european electronic invoices

4357.1M41](/packages/horstoeko-zugferd)[tempest/framework

The PHP framework that gets out of your way.

2.3k42.4k21](/packages/tempest-framework)[bithost-gmbh/pdfviewhelpers

This is a TYPO3 CMS extension that provides various Fluid ViewHelpers to generate PDF documents.

44276.2k3](/packages/bithost-gmbh-pdfviewhelpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
