Font import, metrics, and stack management utilities for PDF generation.
If this project is useful to you, please consider supporting development via GitHub Sponsors.
tc-lib-pdf-font provides font import and runtime font-stack services used by PDF composition engines.
It bridges static font assets and runtime document composition by handling metrics, encodings, and font program references in a PDF-friendly way. This modular design lets applications evolve font workflows independently from the rest of the rendering stack.
| Namespace | \Com\Tecnick\Pdf\Font |
| Author | Nicola Asuni info@tecnick.com |
| License | GNU LGPL v3 - see LICENSE |
| API docs | https://tcpdf.org/docs/srcdoc/tc-lib-pdf-font |
| Packagist | https://packagist.org/packages/tecnickcom/tc-lib-pdf-font |
- Import support for core, Type1, and TrueType sources
- Font metadata extraction and normalization
- Utilities for subset and output dictionary generation
- Font stack insertion and switching
- Glyph width/bounding-box helpers
- Character replacement and fallback handling
- PHP 8.2 or later
- Extensions:
json,pcre,zlib - Composer
composer require tecnickcom/tc-lib-pdf-font<?php
require_once __DIR__ . '/vendor/autoload.php';
$font = new \Com\Tecnick\Pdf\Font\Import('/path/to/font.ttf');
$metrics = $font->getFontMetrics();
var_dump($font->getFontName(), $metrics['type']);For larger examples, refer to test/OutputTest.php and the conversion tooling in this repository.
Use the CLI utilities in util/ to convert existing font files into the JSON/Z format consumed by this library.
Run util/convert.php and pass one or more input files with --fonts:
php util/convert.php \
--outpath=./target/fonts/custom/ \
--type=TrueTypeUnicode \
--flags=32 \
--encoding_id=1 \
--fonts=/path/to/MyFont-Regular.ttf,/path/to/MyFont-Bold.ttfThe command writes generated font definition files to --outpath.
Common options:
--type: Explicit font type (TrueTypeUnicode,TrueType,Type1,CID0JP,CID0KR,CID0CS,CID0CT). Leave empty for autodetect.--encoding: Encoding table (for examplecp1252for many non-Unicode Type1/Core cases). Omit for Unicode and symbolic fonts.--flags: PDF descriptor flags. Default is32(non-symbolic).--platform_idand--encoding_id: CMAP selection for TrueType Unicode imports (defaults:3and1).--linked: Link to system font file instead of embedding/copying it (not transportable).
To see full usage help:
php util/convert.php --helpFor batch generation from the mirrored font set:
cd util
make buildThis installs util dependencies and runs bulk_convert.php, which scans the mirror package and writes converted fonts under target/fonts/.
Notes:
bulk_convert.phpalso attempts OTF conversion via FontForge (fontforge -script otf2ttf.ff ...) before import.- If you run bulk conversion directly, customize destination with
php util/bulk_convert.php --outpath=/your/path/.
make deps
make help
make qaFont generation helpers are also available through Make targets such as fonts.
make rpm
make debFor system packages, bootstrap with:
require_once '/usr/share/php/Com/Tecnick/Pdf/Font/autoload.php';Contributions are welcome. Please review CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.
Nicola Asuni - info@tecnick.com