PHPackages                             francerz/exfpdf - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. francerz/exfpdf

ActiveLibrary[HTTP &amp; Networking](/categories/http)

francerz/exfpdf
===============

Free PDF extension library

v1.0.29(2y ago)21.4k2PHPPHP &gt;=5.4CI failing

Since Sep 22Pushed 2y agoCompare

[ Source](https://github.com/francerz/php-exfpdf)[ Packagist](https://packagist.org/packages/francerz/exfpdf)[ RSS](/packages/francerz-exfpdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (31)Used By (0)

ExFPDF (Extended Free PDF)
==========================

[](#exfpdf-extended-free-pdf)

[![Packagist](https://camo.githubusercontent.com/2a17b610845f2828c03839ae29b517ca5108ee869f16064255010531336d83bc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6672616e6365727a2f457846504446)](https://packagist.org/packages/francerz/ExFPDF)[![Build Status](https://github.com/francerz/ExFPDF/workflows/PHP%20Composer/badge.svg?branch=master)](https://github.com/francerz/ExFPDF/actions?query=workflow%3A%22PHP+Composer%22+branch%3Amaster)

This library extends basic functionality of the FPDF class.

FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

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

[](#installation)

The easiest and optimal way to install ExFPDF is by using [Composer](https://getcomposer.org).

If you already using Composer, just run the next command and will be fully installed.

```
composer require francerz/ExFPDF
```

Extended functionality
----------------------

[](#extended-functionality)

### Output result as PSR-7 ResponseInterface

[](#output-result-as-psr-7-responseinterface)

The ExFPDF allows to output resultant PDF to PSR-7 compliant ResponseInterface object. Relies on PSR-17 Http Factories to create the instances.

```
OutputPsr7(
  \Psr\Http\Message\ResponseFactoryInterface $responseFactory,
  \Psr\Http\Messsage\StreamFactoryInterface $streamFactory,
  string $filename,
  bool $inline = true,
  bool $isUTF8 = false
)
```

Usage example

```
$pdf = new ExFPDF();
// ... create PDF

// ... load HTTP Factories
$responseFactory = new ResponseFactory(); // from a PSR-17 compliant library
$streamFactory = new StreamFactory(); // from a PSR-17 compliant library

// Output PSR-7 file
$response = $pdf->OutputPsr7($responseFactory, $streamFactory, 'my-file.pdf');
```

#### Alternative simplified method `OutputPsr7WithManager`

[](#alternative-simplified-method-outputpsr7withmanager)

Alternatively you can use HttpFactoryManager to handle multiple factories instances to reduce parameters, improving reusability.

```
OutputPsr7WithManager(
  \Francerz\Http\Utils\HttpFactoryManager $hfm,
  string $filename,
  bool $inline = true,
  bool $isUTF8 = false
)
```

Usage example

```
$pdf = new ExFPDF();
// ... create PDF

// Output PSR-7 Response object
$factories = new HttpFactoryManager(new ResponseFactory(), new StreamFactory());
$response = $pdf->OutputPsr7WithManager($factories, 'my-file.pdf');
```

##### Even simplier with in-home HTTP library

[](#even-simplier-with-in-home-http-library)

In the following example is used the simplified version with in-home HTTP library [francerz/http](https://packagist.org/packages/francerz/http) wich is PSR-7, PSR-17 and PSR-18 compliant.

```
$pdf = new ExFPDF();
// ... create PDF

// Output PSR-7 Response object
$response = $pdf->OutputPsr7WithManager(HttpFactory::getManager(), 'my-file.pdf');
```

### Relative Positioning and Sizing

[](#relative-positioning-and-sizing)

Its allowed to use X, Y, Width and Height as percents of current page size.

```
// Sets Y position at 25% (one quarter) from page top.
$pdf->SetY('25%');
// Sets X position at 25% (one quarter) from page left.
$pdf->SetX('25%');

// Draws a cell with 50% width and height of current page size.
$pdf->Cell('50%','50%', '', 1);
```

Also the positioning and sizing can be relative to the page content area, inside the margins.

```
// Sets Y position at top margin.
$pdf->SetY('~0');
// Sets X position at left margin.
$pdf->SetX('~0');

// Draws a cell with 25% width and 10% height of current page content.
$pdf->Cell('~25%', '~10%', '', 1);
```

Therefore, you can get measure calculations with methods `CalcX($x)`, `CalcY($y)`, `CalcWidth($w)` and `CalcHeight($h)`.

### Offset positioning

[](#offset-positioning)

Allows to increase or decrease current position.

```
// translates pointer 10 units right to current X.
$pdf->OffsetX(10);

// translates pointer 20 units bottom to current Y.
$pdf->OffsetY(20);

// translates equivalent to two previous in a single line.
$pdf->OffsetXY(10, 20);

// offset may be negative and relative units
$pdf->OffsetXY(-10, '~10%');
```

### Coordinate Pinning

[](#coordinate-pinning)

It's posible to pin coordinates with a name.

```
MoveToPin($pinName, $axis = 'XY', $offset = 0, $offsetY = 0);
```

```
// Defines a coordinate pin at current X,Y with name 'start'.
$pdf->SetPin('start');

// Retrieves 'start' pin positions.
$x = $pdf->GetPinX('start');
$y = $pdf->GetPinY('start');

// Moves pdf position back to pin 'start'
$pdf->MoveToPin('start');

// Moves pdf X position back to pin 'start'
$pdf->MoveToPin('start','X');

// Moves pdf Y position back to pin 'start'
$pdf->MoveToPin('start','Y');

// Moves pdf X position back to pin 'start' and adds 10 units.
$pdf->MoveToPin('start', 'X', 10);

// Moves pdf Y position back to pin 'start' and adds 20 units.
$pdf->MoveToPin('start', 'Y', 20);

// Moves pdf position back to pin 'start' and adds X: 10 units, Y: 20 units.
$pdf->MoveToPin('start', 'XY', 10, 20);
```

### Relative Cell Height based on Font Size

[](#relative-cell-height-based-on-font-size)

```
SetLineHeight(float $size)
```

Define automatic line height size based on current Font Size.

```
$pdf->SetFontSize(10);
$pdf->SetLineHeight(1.1); // 110% of actual size (11pt)

$pdf->Cell('100%', null, 'This text is size 10pt, but Cell is 11pt height with LineHeight 1.1');
```

### Simplified content encoding

[](#simplified-content-encoding)

```
SetSourceEncoding(string $encoding)
```

Allows internal decoding strings without writing on each cell.

```
$pdf->SetSourceEncoding('UTF-8');
$pdf->Cell('100%', null, 'Benjamín pidió una bebida de kiwi y fresa; Noé, sin vergüenza, la más exquisita champaña del menú.');
```

### Right aligned Cell

[](#right-aligned-cell)

```
CellRight($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $margin=0)
```

Puts a cell aligned to the right margin of the page. Optionally `$margin` can be set to displace the Cell from the right margin.

```
$pdf->CellRight(15, 5, 'Date: ', 0, 0, 'R', false, '', 30);
$pdf->CellRight(30, 5, date('Y-m-d'), 1, 1, 'C', false, '', 0);
```

### Header and Footer

[](#header-and-footer)

Allows to define Header and Footer using anonymous functions.

- `SetHeader(callable $headerFunc, $headerHeight = null)`
    Sets a callable function that will execute when Header is loading. If parameter `$headerHeight` is null, then will be calculated and body content will be displaced. If is set, then content will be displaced `$headerHeight`plus the top margin.
- `SetFooter(callable $footerFunc, $footerHeight = null)`
    Sets a callable function that will execute when Footer is loading. If parameter `$footerHeight` is null, then will be calculated and page break will executed before reaching footer content. If is set, the footer will be displaced from based on page bottom edge.

```
$userName = "My Name";

$pdf = new ExFPDF();
$pdf->AliasNbPages();
$pdf->SetFont('Arial', '', 12);
$pdf->SetHeader(function(ExFPDF $exfpdf) use ($userName) {
    $exfpdf->Cell('~100%', 10, "Hello {$userName}", 1);
});
$pdf->SetFooter(function(ExFPDF $exfpdf) {
    $exfpdf->Cell('~100%', 10, 'Page '.$exfpdf->PageNo(), 1, 0, 'R');
});
$pdf->AddPage();

$pdf->Output('I');
```

> **Note:**
> It's important to invoke `SetHeader()` and `SetFooter()` before `AddPage()`.

### Tables

[](#tables)

Table PDF creation is simplified and with automatic overflowing when cells overflows in multiple pages.

```
$pdf = new ExFPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 12);

// Creates table with three columns with given widths
$table = $pdf->CreateTable(['~25%','~60%','~15%']);

// Sets Line Height as its used to extend cell size.
$pdf->SetLineHeight(1.2);

// Set header styling
$pdf->SetFont('','B', 14);
$pdf->SetFillColor('#CA4A0F');
$pdf->SetTextColor('#FFF');

// Creates a row with heading
$row = $table->AddRow();
$row->Cell('Price', $align='C', $fill=true, $colspan=1, $rowspan=2);  // 2 rows tall
$row->Cell('Product', $align='C', $fill=true, $colspan=2);            // 2 colums wide
$row = $table->AddRow();
$row->CellSpan($fill=true); // $rowspan still not supported this is placeholder
$row->Cell('Description', $align='C', $fill=true);
$row->Cell('Quantity', $align='C', $fill=true);

// Creates content rows
$pdf->SetFont('', '', 12);
$pdf->SetTextColor('#000');

$row = $table->AddRow();
$row->Cell('$ 340.00', $align='R');
$row->Cell('Gymbal');
$row->Cell('3', 'C');
$row = $table->AddRow();
$row->Cell('$ 970.00', $align='R');
$row->Cell('Laptop');
$row->Cell('1', 'C');
$row = $table->AddRow();
$row->Cell('$ 120.00', $align='R');
$row->Cell('Headphones');
$row->Cell('2', 'C');

// Draws all borders in table
$table->DrawBorders();
```

### Barcode support

[](#barcode-support)

```
$pdf->barcode128(string $code, $w, $h, $x = '0+', $y = '0+');
```

Using the `barcode128` puts the given `$code` ASCII string at the given `$x`and `$y` position. And with given `$w` (width) and `$h` (height). This measures are compatible with the relative positioning and sizing.

If no `$x` or `$y` is set, then will be the current PDF position.

```
$pdf->barcode39(string $code, $w, $h, $x, $y);
```

Using the `barcode39` puts the given `$code` (`[-0-9A-Z. *$/+%]`) string at the given `$x` and `$y` position, with the given `$w` (width) and `$h` (height). This meaures are compatible with the relative positioning and sizing.

### QR and DataMatrix support

[](#qr-and-datamatrix-support)

```
$pdf->QrCode(string $data, $size, $level = 'H');
$pdf->DataMatrix(string $data, $size);
```

```
$matrix = $pdf->GetQrCodeMatrix(string $data, $level = 'H');
$pdf->DrawBinaryMatrix($matrix, $size);
```

```
$matrix = $pdf->GetDataMatrixMatrix(string $data);
$pdf->DrawBinaryMatrix($matrix, $size);
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

Every ~35 days

Recently: every ~23 days

Total

30

Last Release

1032d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/630263d156ec44e1d55c3d237fe08354442d0cbe7b257032997d0a649baf1854?d=identicon)[francerz](/maintainers/francerz)

---

Top Contributors

[![francerz](https://avatars.githubusercontent.com/u/10836837?v=4)](https://github.com/francerz "francerz (67 commits)")

---

Tags

fpdfphppsr-7http-messagepdfbarcode

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/francerz-exfpdf/health.svg)

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

###  Alternatives

[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k296.6M807](/packages/symfony-psr-http-message-bridge)[fig/http-message-util

Utility classes and constants for use with PSR-7 (psr/http-message)

39489.0M274](/packages/fig-http-message-util)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

86874.0k94](/packages/httpsoft-http-message)[httpsoft/http-server-request

Infrastructure for creating PSR-7 ServerRequest and UploadedFile

15112.6k29](/packages/httpsoft-http-server-request)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)

PHPackages © 2026

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