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(1y ago)1792↓23.1%1LGPL-3.0-or-laterPHPPHP ^7.4 || ^8.0

Since Feb 26Pushed 1y 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 3w 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

31

—

LowBetter than 66% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

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

691d 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

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[phpro/soap-client

A general purpose SoapClient library

8895.9M52](/packages/phpro-soap-client)[drupal/core

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

19564.8M1.6k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)

PHPackages © 2026

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