PHPackages                             quazardous/pdf-labels - 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. quazardous/pdf-labels

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

quazardous/pdf-labels
=====================

Yet another PDF labels class

4116PHP

Since Jun 23Pushed 9y ago2 watchersCompare

[ Source](https://github.com/quazardous/pdf-labels)[ Packagist](https://packagist.org/packages/quazardous/pdf-labels)[ RSS](/packages/quazardous-pdf-labels/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

pdf-labels
==========

[](#pdf-labels)

Yet another PDF labels class

It's slightly inspired on .

install
=======

[](#install)

```
composer require quazardous/pdf-labels

```

concepts
========

[](#concepts)

PDF Labels was designed to be easily extensible.

Interfaces
----------

[](#interfaces)

I've split up PDF Labels in many simple components/interface. You can write your own components by implementing the requested interface.

### The engine

[](#the-engine)

It's the top/shell class:

- does some validation
- cross acknowledge layout and writer
- fetches the data from the data provider component
- calculates where to put them according with the layout component
- triggers the render with the writer component

### The layout

[](#the-layout)

interface: `LabelLayoutInterface`

A class implementing the layout is responsible to calculate the labels layout/grid taking in account page dimensions, label dimensions, margins, etc.

### The data provider

[](#the-data-provider)

interface: `LabelDataProviderInterface`

Responsible of fetching label data.

### The writer

[](#the-writer)

interface: `LabelWriterInterface`

Responsibe to render the labels to PDF or whatever.

Current implementation
----------------------

[](#current-implementation)

Current implementations provides:

- a simple engine
- 2 data providers (array or callback)
- a 'smart' layout trying to guess what is missing
- a TCPDF writer

Each components can have a different internal unit of length (mm, pt, in).

usage
=====

[](#usage)

Here is a commented example.

```
// A fluid label layout trying to auto fit 50mm x 30mm labels
// See SimpleFluidLabelLayout for more options.
// You can create your own layout with LabelLayoutInterface.
$options = [
    // the bare minimum is label dimensions
    'label_width' => 50,
    'label_height' => 30,
];
$layout = new SimpleFluidLabelLayout($options);

// Some simple labels data. Each row is passed to the render label callback.
// You can create your own data providers with LabelDataProviderInterface.
// see CallbackLabelDataProvider: a callback based data provider usefull to save memory (DB to PDF).
$labels = [
    ['Foo', 'Bar'],
    ['One', 'Two'],
    ['Isaac', 'Asimov'],
    ['Black', 'White'],
...
];

// The main class.
$engine = new LabelEngine($layout, $labels);

// create a TCPDF label writer.
$pdf = new TcPdfLabelWriter();
// add standard TCPDF attributes
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetAuthor('quazardous');

// set the render label callback
// the engine calculate the correct $x and $y
$pdf->setRenderLabelCallback(function ($x, $y, $data) use ($pdf) {
    $aff_border = 0;
    $pdf->SetFont("helvetica");
    $pdf->setX($x);
    $pdf->setY($y, false);
    $pdf->Cell(0 , 0, $data[0], $aff_border, 1, 'L', 0);
    $pdf->setX($x);
    $pdf->setY($y + 6, false);
    $pdf->Cell(0 , 0, $data[1], $aff_border, 1, 'L', 0);
});

// register the label writer with the engine
$engine->setWriter($pdf);

// main loop:
// fetch data row/label and for each we trigger the render label callback.
$engine->populate();

// standard TCPDF generation
$pdf->Output(__DIR__ . "/gen/example1.pdf", "F");
```

tests
=====

[](#tests)

Copy and adapt the file tests/config-dist.php to tests/config.php then run:

```
composer install
phpunit

```

A sample PDF file is generated in `tests/gen`.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f9b424f56493e5f1fa6ae1edf6552cefbb24755fd9949618e57c9373edcd8ce6?d=identicon)[quazardous](/maintainers/quazardous)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/quazardous-pdf-labels/health.svg)

```
[![Health](https://phpackages.com/badges/quazardous-pdf-labels/health.svg)](https://phpackages.com/packages/quazardous-pdf-labels)
```

###  Alternatives

[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.2k57.6M131](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)[setasign/tfpdf

This class is a modified version of FPDF that adds UTF-8 support. The latest version is based on FPDF 1.85.

426.1M30](/packages/setasign-tfpdf)[aspera/xlsx-reader

Spreadsheet reader library for XLSX files

52742.2k5](/packages/aspera-xlsx-reader)

PHPackages © 2026

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