Skip to content
getnextpdf.com

Pro edition

Font Tools

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.

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.

Terminal window
composer require nextpdf/pro:^3

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. FontDesubsetter scans raw PDF data for /BaseFont entries, recognizes the subset prefix pattern, and reports each entry as a SubsetInfo value object with the original family name, subset glyph count, full glyph count, and encoding.
  • Plans de-subsetting. DesubsetPlan collects 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.

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.

ClassResponsibility
FontDesubsetterScan PDF data and report subset font entries.
SubsetInfoImmutable description of one detected subset.
DesubsetPlanTargeted subsets plus estimated size increase.
use NextPDF\Pro\FontTools\FontDesubsetter;
$subsets = (new FontDesubsetter())->analyzeSubsets($pdfBytes);
foreach ($subsets as $info) {
echo $info->baseFont . ': ' . $info->subsetGlyphCount . " glyphs\n";
}
use NextPDF\Pro\FontTools\FontDesubsetter;
$desubsetter = new FontDesubsetter();
$subsets = $desubsetter->analyzeSubsets($pdfBytes);
$logger->info('fonttools.scan', ['subset_count' => count($subsets)]);
  • The scanner reports a /BaseFont without 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 /BaseFont entries; encrypted or heavily compressed object streams may need decoding first.

Subset scanning is linear in PDF byte length. Planning is linear in the number of detected subsets.

Font Tools reads structural metadata only. It does not execute font programs or resolve external font references.

BehaviorReferenceStatus
Subset font naming conventionISO 32000-2 §9.9.2Aligned (paraphrased)
  • FontDesubsetter::analyzeSubsets() scans raw PDF data for /BaseFont entries, recognizes the six-letter-uppercase-plus-+ subset prefix, and returns each as an immutable SubsetInfo with the original family name, subset glyph count, full glyph count, and encoding.
  • A /BaseFont without the subset prefix is reported as a non-subset entry rather than skipped.
  • DesubsetPlan collects 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 does not change Font Tools behavior. Enterprise adds higher-tier features documented separately; they are not required for subset detection or de-subset planning.

NextPDF Core’s open-source font pipeline handles base font embedding. Subset accounting and de-subset planning are Pro additions. See /modules/font/.

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.