Table of contents
tc-lib-pdf delegates font parsing, subsetting, embedding, and generated font data to tc-lib-pdf-font.
How the Font Stack Is Split
tc-lib-pdf: document generation, text layout, and PDF output orchestration.tc-lib-pdf-font: font loading, parsing, subsetting, embedding, and font data generation.
This package boundary keeps the core PDF engine focused and lets the font pipeline evolve independently.
Supported Font Types
The tc-lib ecosystem supports the major font classes expected in production PDF workflows:
- TrueType Unicode (UTF-8)
- OpenType Unicode (v1)
- TrueType
- OpenType (v1)
- Type1
- CID-0
- PDF core (standard) fonts
Embedding and Subsetting
Choose the embedding model based on delivery constraints and interoperability requirements:
- Full embedding: Best compatibility across readers and operating systems.
- Subsetting: Smaller output by embedding only the glyphs used in the document.
- Non-embedded usage (where applicable): Smaller files, but rendering depends on client-side font availability.
For public distribution, embedding with subsetting is usually the safest default.
Font Setup
When you install tc-lib-pdf as a dependency, the fonts from the companion tc-lib-pdf-font package must be generated before they can be used.
Composer does not execute scripts declared by dependencies, so add the font generation step to your consuming project:
{
"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"
],
"post-autoload-dump": [
"@tc-lib-pdf-fonts"
]
}
}
This covers composer install, composer update, composer require, and composer dump-autoload.
If you prefer manual generation:
make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts
Generated fonts are cached under vendor/tecnickcom/tc-lib-pdf-font/target/fonts/.
Custom Font Import
For a runnable end-to-end workflow, see /examples/E072_import_new_font/.
Example 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 the generated directory before creating the Tcpdf instance:
\define('K_PATH_FONTS', '/opt/app/fonts/tc-lib-pdf');
For shared or immutable environments, generate fonts once into a persistent directory outside vendor/ and reuse that path across deployments.
Practical Guidance
- Use Unicode-capable fonts for multilingual and right-to-left text.
- Validate fallback behavior for missing glyphs early in development.
- Keep font licensing and provenance explicit in your build and release pipeline.
- Prefer persistent generated font directories when dependency reinstalls are common.
Installation References
Install the full PDF stack:
composer require tecnickcom/tc-lib-pdf
Install the font package directly when integrating font workflows in isolation:
composer require tecnickcom/tc-lib-pdf-font
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) |
References
- tc-lib-pdf overview: /
- tc-lib-pdf API docs: /docs/srcdoc/tc-lib-pdf
- tc-lib-pdf-font project page: /projects/tc-lib-pdf-font/
- tc-lib-pdf-font API docs: /docs/srcdoc/tc-lib-pdf-font
Previous: /docs/cache/
Overview: /docs/
Next: /docs/development/