PHPackages                             heimrichhannot/pdf-creator - 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. heimrichhannot/pdf-creator

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

heimrichhannot/pdf-creator
==========================

PdfCreator is a high level API for PDF file creating with PHP.

0.4.3(2y ago)1827↓47.6%1LGPL-3.0-or-laterPHPPHP ^7.4 || ^8.0

Since Feb 26Pushed 2y ago6 watchersCompare

[ Source](https://github.com/heimrichhannot/pdf-creator)[ Packagist](https://packagist.org/packages/heimrichhannot/pdf-creator)[ RSS](/packages/heimrichhannot-pdf-creator/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (10)Dependencies (3)Versions (11)Used By (1)

PDF Creator
===========

[](#pdf-creator)

PdfCreator is a high level API for PDF file creating with PHP. Its goal is to make usage of existing libraries easier and object-orientated.

Features
--------

[](#features)

- supported libraries:
    - [Dompdf](https://github.com/dompdf/dompdf)
    - [mPDF](https://github.com/mpdf/mpdf)
    - [TCPDF](https://github.com/tecnickcom/TCPDF)

Example
-------

[](#example)

```
use HeimrichHannot\PdfCreator\Concrete\MpdfCreator;
use HeimrichHannot\PdfCreator\PdfCreatorFactory;

$pdf = PdfCreatorFactory::createInstance(MpdfCreator::getType());
$pdf->setHtmlContent($this->compile())
    ->setFilename($this->getFileName())
    ->setFormat('A4')
    ->setOrientation($pdf::ORIENTATION_PORTRAIT)
    ->addFont(
        "/path_to_project/assets/fonts/my_great_font.tff",
        "myGreatFont",
        $pdf::FONT_STYLE_REGUALAR,
        "normal"
    )
    ->setMargins(15, 10, 15,10)
    ->setTemplateFilePath("/path_to_project/assets/pdf/mastertemplate.pdf")
    ->setOutputMode($pdf::OUTPUT_MODE_DOWNLOAD)
    ->render()
;
```

Usage
-----

[](#usage)

### Install

[](#install)

We recommend installing this library with composer:

```
composer require heimrichhannot/pdf-creator

```

You also need to install the pdf library, you want to use this bundle with:

- Dompdf (version 1 to 3 are supported):
    - `"dompdf/dompdf": "^3.0"`
    - if you want to use master templates in Dompdf, you also need FPDI and TCPDF:
        - `"tecnickcom/tcpdf": "^6.3"`
        - `"setasign/fpdi": "^2.3"`
- mPDF (version 7 and 8 are supported):
    - `"mpdf/mpdf": "^8.0"`
- TCPDF
    - `"tecnickcom/tcpdf": "^6.3"`
    - if you want to use master templates in TCPDF, you also need FPDI:
        - `"setasign/fpdi": "^2.3"`

If you're using [Contao](https://contao.org/), you could try the [PDF Creator Bundle](https://github.com/heimrichhannot/contao-pdf-creator-bundle), which is based on this library.

### Use callback for custom adjustments

[](#use-callback-for-custom-adjustments)

Due the high level approach not all specific library functionality could be supported. To add specific configuration, you can use the callback mechanism comes with this api.

CallbackDescriptionBeforeCreateLibraryInstanceCallbackIs evaluated before the library instance is created and allows to modifiy the constructor parameters.BeforeOutputPdfCallbackIs evaluated before the library method to output the pdf is called and provide the library instance and the output method parameters.```
use HeimrichHannot\PdfCreator\BeforeCreateLibraryInstanceCallback;
use HeimrichHannot\PdfCreator\BeforeOutputPdfCallback;
use HeimrichHannot\PdfCreator\Concrete\MpdfCreator;
use HeimrichHannot\PdfCreator\PdfCreatorFactory;

$pdf = PdfCreatorFactory::createInstance(MpdfCreator::getType());

$pdf->setBeforeCreateInstanceCallback(function (BeforeCreateLibraryInstanceCallback $callbackData) {
    $parameter = $callbackData->getConstructorParameters();
    $parameter['config']['fonttrans'] = [
        'rotis-sans-serif-w01-bold' => 'rotis-sans-serif',
        'rotissansserifw01-bold' => 'rotis-sans-serif',
    ];
    $callbackData->setConstructorParameters($parameter);
    return $callbackData;
});

$pdf->setBeforeOutputPdfCallback(function (BeforeOutputPdfCallback $callbackData) use ($pdf) {
    $mpdf = $callbackData->getLibraryInstance();
    $mpdf->AddPage();
    $parameters = $callbackData->getOutputParameters();
    $parameters['name'] = 'custom_'.$pdf->getFilename();
    $callbackData->setOutputParameters($parameters);
});
```

### Use return value

[](#use-return-value)

The render method return an `PdfCreatorResult` instance. It contains the output mode and filepath or filecontent for corresponding output modes.

```
use HeimrichHannot\PdfCreator\Concrete\DompdfCreator;
use HeimrichHannot\PdfCreator\PdfCreatorFactory;

$pdf = PdfCreatorFactory::createInstance(DompdfCreator::getType());
$result = $pdf->setOutputMode($pdf::OUTPUT_MODE_FILE)
    // ...
    ->render()
;
$filepath = $result->getFilePath();

$pdf = PdfCreatorFactory::createInstance(DompdfCreator::getType());
$result = $pdf->setOutputMode($pdf::OUTPUT_MODE_STRING)
    // ...
    ->render()
;
$filepath = $result->getFileContent();
```

Documentation
-------------

[](#documentation)

- [API Documentation](https://heimrichhannot.github.io/pdf-creator/)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

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

Every ~139 days

Recently: every ~291 days

Total

10

Last Release

737d ago

PHP version history (2 changes)0.1.0PHP ^7.2

0.4.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/28ad3224d8727b622ebd229840eea6b9dbcb83eb0bd609e6ce65b614830ff538?d=identicon)[digitales@heimrich-hannot.de](/maintainers/digitales@heimrich-hannot.de)

---

Top Contributors

[![koertho](https://avatars.githubusercontent.com/u/12064642?v=4)](https://github.com/koertho "koertho (39 commits)")

### Embed Badge

![Health badge](/badges/heimrichhannot-pdf-creator/health.svg)

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

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k199.6M3.3k](/packages/composer-composer)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k19](/packages/tempest-framework)[contao/core-bundle

Contao Open Source CMS

1301.7M3.0k](/packages/contao-core-bundle)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k6.0M766](/packages/sylius-sylius)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19467.3M1.9k](/packages/drupal-core)[shopware/platform

The Shopware e-commerce core

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

PHPackages © 2026

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