THotPDF.SubsetLoadedFonts Method

Rewrites supported embedded TrueType, OpenType CFF, raw CFF, and Type 1 programs so they retain only glyphs reachable from loaded-document content

Declaration

function SubsetLoadedFonts(
    const Options: THPDFLoadedFontSubsetOptions;
    out AInfo: THPDFLoadedFontSubsetInfo): Integer; overload;
function SubsetLoadedFonts(
    out AInfo: THPDFLoadedFontSubsetInfo): Integer; overload;

Reachability

Page content is always scanned, including text-showing operators and resource-local font selections

IncludeFormXObjects recursively includes invoked Form XObjects with inherited resources, cycle detection and a bounded nesting depth

IncludeAnnotationAppearances includes normal, rollover and down appearances as well as state dictionaries, and also follows Form XObjects used by those appearances when enabled

Every character code follows its declared encoding, then any Type0 CMap and CIDToGIDMap, before reaching the stable embedded glyph ID; existing CID maps and ToUnicode data are not renumbered

TrueType composite glyphs retain their recursive component closure, while COLR v0 layers and COLR v1 glyph paint dependencies retain every referenced outline

Type 1 simple fonts follow Standard, WinAnsi, MacRoman, or MacExpert encoding plus Differences, then rewrite unused CharStrings in PFB, PDF split binary, or hex PFA data without changing the embedded stream layout

Options

FieldDefaultMeaning
MinimumSavingsBytes1Minimum encoded stream reduction required before a candidate is adopted
EnforceSignaturePermissionsTrueRefuse every rewrite when the document contains a signature field
IncludeFormXObjectsTrueTrace invoked nested Form XObjects
IncludeAnnotationAppearancesTrueTrace annotation appearance streams and states

Result and safety

The return value is the number of embedded font programs rewritten, while AInfo reports scan coverage, mapping or decoding failures, used glyphs, byte savings and signature consequences

A font program is left byte-for-byte unchanged when any reachable code cannot be mapped, its format is unsupported, subsetting fails, or the encoded candidate misses the savings threshold

Type 1 rewriting fails closed for multiple binary PFB segments, an unparseable explicit simple-font encoding, a missing requested glyph name, or an unsupported CharString layout; unknown COLR versions and sfnt programs without sparse outline tables also remain unchanged

All candidates are analyzed before mutation, and the default signature policy returns zero with RefusedBySignaturePolicy set; disabling the policy permits rewriting and sets SignaturesInvalidated whenever a signed document changes

Example

var
  Info: THPDFLoadedFontSubsetInfo;
begin
  PDF.LoadFromFile('input.pdf');
  if PDF.SubsetLoadedFonts(Info) > 0 then
    PDF.SaveToFile('subset.pdf');
end;

Resource and Image Optimization