PHPackages                             jbtronics/dompdf-font-loader-bundle - 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. jbtronics/dompdf-font-loader-bundle

ActiveSymfony-bundle[PDF &amp; Document Generation](/categories/documents)

jbtronics/dompdf-font-loader-bundle
===================================

A symfony bundle to easily load custom fonts for dompdf (on cache warming)

v1.1.6(7mo ago)247.4k↑27.1%2MITPHPPHP ^8.1

Since Jul 2Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/jbtronics/dompdf-font-loader-bundle)[ Packagist](https://packagist.org/packages/jbtronics/dompdf-font-loader-bundle)[ RSS](/packages/jbtronics-dompdf-font-loader-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (8)Dependencies (6)Versions (9)Used By (0)

Font loader for dompdf Bundle
=============================

[](#font-loader-for-dompdf-bundle)

This bundle provides a simple way to load/install fonts of your choice for the [dompdf](https://github.com/dompdf/dompdf) library in a symfony project. This bundle offers functionality to load font families programmatically or automatically on cache warmup. You can specify each font family with a name and a path to the font files or you let the bundle autodiscover all fonts in a directory.

Feautures
---------

[](#feautures)

- Services for easy installation of font families
- Configure font families in your config files, which will be loaded automatically on cache warmup
- Autodiscover all fonts in configured directories

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

[](#requirements)

- Symfony 6+
- PHP 8.1 or later

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

[](#installation)

1. Install the bundle `composer require jbtronics/dompdf-font-loader-bundle`
2. Enable the bundle in your `config/bundles.php` (normally done by Symfony flex automatically)
3. Put the font TTF files you want to use in a directory the webserver can access (preferably somewhere in your project folder)
4. Add a config file `config/packages/jbtronics_dompdf_font_loader.yaml`, with the content described below (and changed according to your need)

Configuration
-------------

[](#configuration)

```
dompdf_font_loader:

  # Set this to true to enable the automatic font loading on cache warmup, without it you have to load the fonts
  # manually via the ConfiguredFontsInstaller service
  auto_install: true

  # You can specify font families here manually
  fonts:
    my_font: # The name of the font family (used to access it in dompdf later)
      # A font family consists of up to four font files (normal, bold, italic, bold_italic)
      normal: "%kernel.project_dir%/assets/fonts/my_font.ttf"
      bold: "%kernel.project_dir%/assets/fonts/my_font_bold.ttf"
      italic: "%kernel.project_dir%/assets/fonts/my_font_italic.ttf"
      bold_italic: "%kernel.project_dir%/assets/fonts/my_font_bold_italic.ttf"

    # But only the normal font file is required, the others can be omitted
    unifont:
      normal: "%kernel.project_dir%/assets/fonts/unifont.ttf"

  # Autodiscover allows you to specify directories, where all fonts will be loaded automatically
  autodiscovery:
    # Each of this directory will be scanned for font files
    paths:
      - "%kernel.project_dir%/assets/fonts"
      - "%kernel.project_dir%/vendor/fonts/package/ttfs"
    exclude_patterns:
      # You can exclude certain patterns from the autodiscovery if you want
       - "exclude_this_font.ttf"
```

The fonts and autodiscovery keys are both optional, but at least one of them is required to load fonts.

Usage
-----

[](#usage)

When you have enabled the `auto_install` option, you do not have to do anything else, the fonts will be loaded automatically on cache warmup (when `php bin/console cache:clear` is run). The bundle will copy the font files to the dompdf font directory, create font metrics and register them in the dompdf library.

### Autodiscovery

[](#autodiscovery)

The autodiscovery mechanism will scan the configured directories for TTF files and register them as font families with the name of the font file. It also tries to detect the type of the font based on a suffix: `_bold` or `_b` will be detected as bold fonts, `_italic`, `_i` as italic fonts, and `_bold_italic` or `_bi` as bold italic. So the `my_font_bold.ttf` will be registered as bold font of the `my_font` family and so on, while `my_font.ttf` will be registered as normal font of the `my_font` family.

In principle dompdf should be able to use OTF files as well, however in my tests it did not work, so autodiscovery only detects TTF files by default. You can change the detected file types via the `autodiscovery.file_pattern` option.

### Specify DOMPDF font location

[](#specify-dompdf-font-location)

Dompdf has its own font directory, where it stores the font files and metrics. This is configured on a per instance basis on a dompdf object with the `set_option('fontDir', $path)` method. To specify the font directory for the dompdf instance used by this bundle, you must decorate the `DompdfFactoryInterface` and configure the object in the `create()` method:

```
#[AsDecorator(decorates: DompdfFactoryInterface::class)]
class MyDompdfFactory implements DompdfFactoryInterface
{
    public function create(): Dompdf
    {
        return new Dompdf(['fontDir' => '%kernel.project_dir%/var/dompdf/fonts']);
    }
}
```

### Manual font loading/installation

[](#manual-font-loadinginstallation)

This bundle offers the `DompdfFontLoader` service, which can be used to install font families manually. You can either install a single font family with the `installFontFamily()` method or install all found fonts in a folder with the `autodiscoverAndInstallFonts()` method.

License
-------

[](#license)

This bundle is licensed under the MIT license. See [LICENSE](LICENSE) for details.

Credits
-------

[](#credits)

- [dompdf](https://github.com/dompdf/dompdf)
- This bundle was inspired by the offical dompdf util script [load\_font.php](https://github.com/dompdf/utils/blob/master/load_font.php)

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance65

Regular maintenance activity

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.7% 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 ~126 days

Recently: every ~135 days

Total

8

Last Release

214d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/966f0c4a6fd593c7a9e3e0c950f4e44dfa6caaf09609500cdce765b1eba7a855?d=identicon)[jbtronics](/maintainers/jbtronics)

---

Top Contributors

[![jbtronics](https://avatars.githubusercontent.com/u/5410681?v=4)](https://github.com/jbtronics "jbtronics (11 commits)")[![monoxide13](https://avatars.githubusercontent.com/u/6792247?v=4)](https://github.com/monoxide13 "monoxide13 (1 commits)")

---

Tags

dompdffontssymfonysymfony-bundlesymfonydompdfSymfony Bundlefonts

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jbtronics-dompdf-font-loader-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/jbtronics-dompdf-font-loader-bundle/health.svg)](https://phpackages.com/packages/jbtronics-dompdf-font-loader-bundle)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

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

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[sulu/sulu

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

1.3k1.4M203](/packages/sulu-sulu)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54681.3k18](/packages/solspace-craft-freeform)

PHPackages © 2026

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