PHPackages                             setasign/setafpdf - 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. setasign/setafpdf

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

setasign/setafpdf
=================

SetaFPDF is a clone of FPDF with an almost compatible interface while using SetaPDF-Core internally for the PDF generation.

v1.0.4(4mo ago)21101.4k↑20.4%9[3 issues](https://github.com/Setasign/SetaFPDF/issues)MITPHPPHP &gt;=7.1CI failing

Since Jan 22Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/Setasign/SetaFPDF)[ Packagist](https://packagist.org/packages/setasign/setafpdf)[ Docs](https://www.setasign.com)[ RSS](/packages/setasign-setafpdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (9)Used By (0)

SetaFPDF
========

[](#setafpdf)

SetaFPDF is a clone of [FPDF](http://www.fpdf.org/) with an almost compatible interface while using [SetaPDF-Core](https://www.setasign.com/core) internally for the PDF generation.

Motivation
----------

[](#motivation)

The main motivation for this project was to be able to create PDF/A documents in PHP without changing all existing PDF generation scripts which rely on [FPDF](http://www.fpdf.org/).

FPDF is a wide spread and very common PHP library for PDF generation. It is small, well tested and runs on millions of websites. It also comes with several extensions and an active [forum](http://fpdf.org/phorum/).

The [SetaPDF-Core](https://www.setasign.com/core) component is a PHP component which allows PHP developers to interact with existing PDF documents on a low level. While there is no high-level API for PDF generation it comes with all low-level features which are required to create PDF/A documents:

- TrueType font sub-setting
- Access to XMP metadata
- Color profiles
- Support for embedded files / attachments

Additionally it comes with other nice features which would be available automatically:

- Access to document outlines
- Access to page labels
- Support for annotations
- Support for creating and handling destinations (also named destinations)
- Support for individual actions
- Support for other colors and color spaces
- Standard and public key encryption (up to AES256)
- ...and much more...

Bringing both SetaPDF and FPDF together result in SetaFPDF: An almost identical interface of FPDF backed up by SetaPDF on the lower level.

### Future of this project

[](#future-of-this-project)

This project is not a start of a new PDF generation project in PHP but it is a temporary solution to improve existing projects which rely on FPDF.

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

[](#requirements)

- PHP &gt;= 7.2
- [SetaPDF-Core](https://www.setasign.com/core) (All [SetaPDF products](https://www.setasign.com/products/) include SetaPDF-Core)
    - [iconv](http://www.php.net/iconv) or [Multibyte String](http://www.php.net/mbstring)
    - [OpenSSL](http://php.net/openssl)
    - [Zlib](http://www.setasign.com/support/faq/setapdf/system-requirements/)

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

[](#installation)

Add following to your composer.json:

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

and execute `composer update`. You need to define the `repository` to evaluate the dependency to the [SetaPDF-Core](https://www.setasign.com/core) component (see [here](https://getcomposer.org/doc/faqs/why-can%27t-composer-load-repositories-recursively.md) for more details).

### Without Composer

[](#without-composer)

Make sure, that the [SetaPDF-Core](https://www.setasign.com/core) component is [installed](https://manuals.setasign.com/setapdf-core-manual/installation/#index-2) and its [autoloader is registered](https://manuals.setasign.com/setapdf-core-manual/getting-started/#index-1) correctly.

Then simply require the `src/autoload.php` file or register following namespaces in your own PSR-4 compatible autoload implementation:

```
$loader = new \Example\Psr4AutoloaderClass;
$loader->register();
$loader->addNamespace('setasign\SetaFpdf', 'path/to/src');
```

Usage
-----

[](#usage)

You can use SetaFPDF the same way as FPDF. Their interfaces are almost identically. So just use another constructor and be aware of following differences:

- The `AddFont()` method was changed to allow only TrueType fonts instead of FPDF font definition files.
- The method `AliasNbPages()` will throw an `\SetaPDF_Exception_NotImplemented` exception throughout. It is removed in favor of a more clean solution by re-accessing the pages afterwards through the `SetPage()` method. By doing this e.g. the alignment is more consistent than with the *marker*.
- The `$isUTF8` parameter is removed from the `Output()` method. The HTTP header is always send with an UTF-8 variant by SetaPDF.
- The `$isUTF8` parameter is removed from following methods: `SetAuthor()`, `SetCreator()`, `SetKeywords()`, `SetSubject()` and `SetTitle()`. You need to pass the parameters in UTF-8 throughout.
- The method `SetCompression()` will throw an `SetaPDF_Exception_NotImplemented` exception if called with `false` as its argument (SetaPDF has no option to turn compression off).
- There's no `Error()` method anymore. Exceptions are thrown where the errors occur.

Improved and new methods:

- The `SetDrawColor()`, `SetTextColor()` and `SetFillColor()` accept 1 argument (0-255) for grayscale colors, 3 arguments (each 0-255) for RGB and 4 arguments (each 0-100) for CMYK now by default.
- A new method `SetPage()` is introduced to allow you to navigate between pages. With it you can e.g. write page numbers and the final page count into the pages footer or header. This was done before with `AliasNbPages()`.
- The new `getPageCount()` method is self-explaining.
- The `getManager()` method allows you to get access to the underlaying object structure.

### Examples and update information

[](#examples-and-update-information)

A simple example will look like:

```
