Pro edition
Font Tools
At a glance
Section titled “At a glance”NextPDF Pro inspects embedded font programs, identifies subset fonts by their standard naming convention, and produces a structured de-subsetting plan with an estimated size impact.
Availability & licensing
Section titled “Availability & licensing”This capability ships in NextPDF Pro (nextpdf/pro) and activates with a Pro-tier license envelope. A deployment without that entitlement does not load the capability’s classes. Compare editions and get a license.
No per-feature license flag gates this module. The Font Tools classes are available whenever nextpdf/pro is installed.
Install
Section titled “Install”composer require nextpdf/pro:^3Conceptual overview
Section titled “Conceptual overview”Subset fonts in a PDF embed only the glyphs the document uses. By convention their /BaseFont name carries a six-letter uppercase tag followed by +, for example ABCDEF+Arial. NextPDF Pro:
- Detects subsets.
FontDesubsetterscans raw PDF data for/BaseFontentries, recognizes the subset prefix pattern, and reports each entry as aSubsetInfovalue object with the original family name, subset glyph count, full glyph count, and encoding. - Plans de-subsetting.
DesubsetPlancollects the subset fonts targeted for replacement with full font programs and reports an estimated byte-size increase, so you can decide whether de-subsetting is worth the file-size cost before acting.
Font Tools is an analysis and planning layer. It describes what is present and what de-subsetting would cost; it does not itself rewrite the font program.
Why it works this way
Section titled “Why it works this way”Rewriting an embedded font program is the hard, risky part. Glyph outlines, hinting, and cmap tables must stay consistent, and one mistake corrupts rendering. So NextPDF Pro splits the cheap, safe work — inventory and cost projection — from that expensive rewrite. The scanner reads bytes only; it never parses or executes a font program, so it stays deterministic and side-effect free. Glyph counts and the size delta are labelled heuristics on purpose, so a capacity call stays honest instead of trusting a number the module cannot measure. That lets you weigh whether de-subsetting is worth the cost before sourcing full font programs.
Design background: Fonts: the hard part.
API surface
Section titled “API surface”| Class | Responsibility |
|---|---|
FontDesubsetter | Scan PDF data and report subset font entries. |
SubsetInfo | Immutable description of one detected subset. |
DesubsetPlan | Targeted subsets plus estimated size increase. |
Code sample — Quick start
Section titled “Code sample — Quick start”use NextPDF\Pro\FontTools\FontDesubsetter;
$subsets = (new FontDesubsetter())->analyzeSubsets($pdfBytes);foreach ($subsets as $info) { echo $info->baseFont . ': ' . $info->subsetGlyphCount . " glyphs\n";}Code sample — Production
Section titled “Code sample — Production”use NextPDF\Pro\FontTools\FontDesubsetter;
$desubsetter = new FontDesubsetter();$subsets = $desubsetter->analyzeSubsets($pdfBytes);$logger->info('fonttools.scan', ['subset_count' => count($subsets)]);Edge cases & gotchas
Section titled “Edge cases & gotchas”- The scanner reports a
/BaseFontwithout the six-letter prefix as a non-subset entry rather than skipping it. - The estimated size increase is a heuristic based on average bytes per glyph, not a measured value.
- Detection works on the byte representation of
/BaseFontentries; encrypted or heavily compressed object streams may need decoding first.
Performance
Section titled “Performance”Subset scanning is linear in PDF byte length. Planning is linear in the number of detected subsets.
Security notes
Section titled “Security notes”Font Tools reads structural metadata only. It does not execute font programs or resolve external font references.
Conformance
Section titled “Conformance”| Behavior | Reference | Status |
|---|---|---|
| Subset font naming convention | ISO 32000-2 §9.9.2 | Aligned (paraphrased) |
Behavior contract
Section titled “Behavior contract”FontDesubsetter::analyzeSubsets()scans raw PDF data for/BaseFontentries, recognizes the six-letter-uppercase-plus-+subset prefix, and returns each as an immutableSubsetInfowith the original family name, subset glyph count, full glyph count, and encoding.- A
/BaseFontwithout the subset prefix is reported as a non-subset entry rather than skipped. DesubsetPlancollects the subsets targeted for replacement and reports an estimated byte-size increase based on average bytes per glyph — a heuristic, not a measured value.- This is an analysis and planning layer. It reports what is present and what de-subsetting would cost; it does not rewrite the font program, execute font programs, or resolve external font references.
Enterprise boundary note
Section titled “Enterprise boundary note”Enterprise does not change Font Tools behavior. Enterprise adds higher-tier features documented separately; they are not required for subset detection or de-subset planning.
Core fallback / alternative
Section titled “Core fallback / alternative”NextPDF Core’s open-source font pipeline handles base font embedding. Subset accounting and de-subset planning are Pro additions. See /modules/font/.
Publication boundary
Section titled “Publication boundary”This page documents externally observable behavior and the supported public API surface only. Internal namespace paths, helper classes, mechanism tables, runbook filenames, and ticket prefixes are out of scope.
See also
Section titled “See also”- Font Tools — Deep Reference — API contract, behavior, and failure modes.
- Optimizer — file-size optimization.
- Core font module — open-source font handling.