Fonts
July 16, 2026 ยท View on GitHub
Back to root overview: README.md
Font Setup
When you install tc-lib-pdf as a dependency in your project (via composer require or composer install), the fonts from the companion package tc-lib-pdf-font must be generated before they can be used.
Composer does not execute scripts declared by dependencies, so you need to add the font generation step to your consuming project's composer.json file:
{
"scripts": {
"tc-lib-pdf-fonts": [
"[ -d vendor/tecnickcom/tc-lib-pdf-font ] && make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts || true"
],
"post-install-cmd": [
"@tc-lib-pdf-fonts"
],
"post-update-cmd": [
"@tc-lib-pdf-fonts"
]
}
}
This ensures fonts are generated automatically when you run:
composer install
composer update
composer require ...
To also cover composer dump-autoload (used in many CI pipelines), add the hook to post-autoload-dump as well:
"post-autoload-dump": [
"@tc-lib-pdf-fonts"
]
If you prefer to generate fonts manually, run the build in the tc-lib-pdf-font package:
cd vendor/tecnickcom/tc-lib-pdf-font
make fonts
Equivalent one-liner from your project root:
make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts
Once fonts are generated, they are cached in vendor/tecnickcom/tc-lib-pdf-font/target/fonts/ and will not be regenerated unless explicitly rebuilt.
You can also add your own fonts and generate their PHP font data with tc-lib-pdf-font. For shared or immutable environments, generate them once into a persistent directory you control (outside vendor/) and point K_PATH_FONTS to that location.
For a runnable end-to-end custom font workflow, see examples/E072_import_new_font.php.
Example import commands (from the project root):
mkdir -p target/fonts/source target/fonts/custom
curl -fL --retry 3 -o target/fonts/source/NotoSans-Regular.ttf \
https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSans/NotoSans-Regular.ttf
php vendor/tecnickcom/tc-lib-pdf-font/util/convert.php \
--outpath=target/fonts/custom \
--type=TrueTypeUnicode \
--flags=32 \
--encoding_id=1 \
--fonts=target/fonts/source/NotoSans-Regular.ttf
Then point K_PATH_FONTS to target/fonts/custom (or an absolute path to that directory) before creating the Tcpdf instance.
\define('K_PATH_FONTS', '/opt/app/fonts/tc-lib-pdf');
This avoids regenerating fonts on every dependency reinstall and lets multiple deployments reuse the same prepared font set.
Third-Party Fonts
PHP font metadata files under the fonts directory are covered by the project license (GNU LGPL v3). They can be regenerated with the built-in font utilities.
Original source files are renamed for compatibility and compressed with PHP gzcompress (.z extension) where applicable.
| Prefix | Source | License |
|---|---|---|
freefont | GNU FreeFont | GNU GPL v3 |
pdfa | tc-font-pdfa (derived from GNU FreeFont) | GNU GPL v3 |
dejavu | DejaVu Fonts 2.35 | Bitstream Vera (with DejaVu public-domain changes) |
unifont | GNU Unifont 15.1.03 | GPL v2+ with font embedding exception (also distributed under SIL OFL 1.1) |
cid0 | GNU Unifont (CID mappings) | GPL v2+ with font embedding exception |
core | Adobe Core14 AFM | Adobe copyright terms (see AFM notices) |