export_fonts

Export fonts and a JSON manifest for external editing

Usage

pdftl <input> export_fonts [<spec>...] <dir> [output <output>]

Details

The export_fonts operation extracts embedded and referenced font assets from the PDF, writes their binary programs (.ttf, .otf, .pfb) to a directory, and compiles their wrapping metrics (/Widths, /W, /Differences) and /ToUnicode mappings into a unified, structured JSON file.

This unifies character code mappings and layout metrics into a single sidecar file: font_{obj_id}_{gen_id}_{name}.json

This file contains character-by-character definitions of both layout metrics (width) and semantic mappings (unicode) using a unified hexadecimal indexing schema. It also carries a top-level width_sync_mode field (default auto) that controls how import_fonts reconciles width edits back into the PDF — see import_fonts help for the available modes.

Beyond widths and ToUnicode, the sidecar also carries, when applicable:

  • A descriptor block with the font’s /FontDescriptor properties (FontName, Flags, FontBBox, Ascent/Descent, StemV, Panose, etc).

  • differences / base_encoding, mirroring a Simple font’s /Encoding.

  • encoding_cmap, recording whether a Type0 font’s /Encoding is /Identity-H or /Identity-V.

  • cid_to_gid_map, either "Identity" or a reference to a separate font_{obj_id}_{gen_id}_{name}.cid2gid.json sidecar for an explicit /CIDToGIDMap table.

Type 3 fonts have no font binary at all: their glyph procedures are extracted instead into a font_{obj_id}_{gen_id}_{name}.charprocs text file (one block per glyph), with any embedded inline bitmap images pulled out losslessly as sibling TIFF files.

Arguments

  • <directory>: (Required) The directory where the extracted font files will be saved.

  • [output <manifest.json>]: The file path to save the JSON manifest. If omitted, the manifest is automatically saved as manifest.json inside the specified directory. Specify output - to print the manifest directly to standard output.

  • [tounicode=<json|ps|all>]: Which format to use for /ToUnicode mapping sidecars.

    • json (default): Write high-level unified character mapping JSON.

    • ps: Write raw CMap PostScript stream text.

    • all: Write both formats side-by-side.

  • [page_range]: Optional page ranges to limit the extraction.

Examples

Extract all fonts to ‘my_fonts/’ and save the manifest to ‘my_fonts/manifest.json’.

pdftl in.pdf export_fonts my_fonts

Extract fonts from pages 1-5 into ‘edited_assets/’ and write manifest to ‘manifest.json’.

pdftl in.pdf export_fonts 1-5 edited_assets tounicode=all output manifest.json

Tags: info, metadata, fonts, export

Source: pdftl.operations.export_import_fonts

Read online: https://pdftl.readthedocs.io/en/stable/operations/export_fonts.html

Type: Operation