DEV Community

Cover image for PDF Font Subsetting Principle: Why Can It Reduce Size by 90%?
Uglypear Data
Uglypear Data

Posted on Originally published at uglypear.com

PDF Font Subsetting Principle: Why Can It Reduce Size by 90%?

Original URL: https://www.uglypear.com/en/blog/pdf-font-subsetting-principle.html

Why can PDF font subsetting reduce file size by 90%? This article explains the principle of font subsetting — character usage analysis, CMap table reconstruction, and glyph index remapping, with a complete breakdown of subsetting the Source Han Serif font from 18MB to 0.4MB. Font subsetting is one of the most effective PDF optimization techniques, especially for documents using Chinese fonts.

1. Font File Structure: Why Are Embedded Chinese Fonts So Large

To understand why subsetting works, you first need to know what's inside a font file. TrueType (.ttf) and OpenType (.otf) font files consist of multiple data tables, each responsible for different functions. When embedded in a PDF, these tables are packaged in full, regardless of how many characters the document uses.

As the table above shows, glyph outline data (the glyf or CFF table) accounts for 60%–85% of the font file. A Chinese font contains 20,000 to 70,000 glyphs, with each character's vector outline averaging 300–600 bytes — totaling 10–20MB. A 50-page PDF typically uses only 800–2000 distinct characters, meaning 95%+ of the glyph data is wasted — this is exactly the compression space subsetting exploits.

Data Table Function Typical Share Subsetting Trim?
cmap Character encoding to glyph index mapping 1%–3% Needs rebuild
glyf TrueType glyph outline data 70%–85% Heavily trimmable
CFF OpenType CFF glyph outlines (PostScript) 60%–80% Heavily trimmable
loca Glyph data position index 1%–2% Needs rebuild
hmtx Horizontal metrics (width/advance) 2%–5% Needs rebuild
name Font name, copyright, and other metadata 0.5%–1% Retained
post PostScript name mapping 1%–3% Partial trim

2. Subsetting Principle: Three Steps to Trim Unused Glyphs

The core idea of font subsetting: keep only the glyphs the document actually uses, discard the rest. The implementation has three key steps, each involving precise operations on font table structures.

The first step is scanning the PDF to find all actually displayed characters. Text in PDFs is written into content streams via text operators (Tj for strings, TJ for arrays), with each character corresponding to an encoding. The subsetting tool traverses all pages' content streams, extracts these encodings, then converts them to Unicode code points via the font's current CMap table, ultimately producing a "used character set."

Scanning also needs to handle special cases: ToUnicode CMap (reverse mapping), multi-byte encoding (common in CJK fonts), and subset prefixes for embedded fonts (six-character + sign format). A 50-page Chinese PDF typically scans out 800–2000 distinct Unicode characters; with punctuation and digits, about 1000–2500 glyphs need to be retained.

The CMap table is the font's "directory," recording the glyph index (glyph ID) for each character encoding. An original Chinese font's CMap table contains 20,000 to 70,000 mappings; after subsetting, only the entries for used characters remain. The rebuild also needs to handle multiple encoding subtable formats.

This is the most critical and complex step. In the original font, glyph indices (GIDs) run consecutively from 0 to N, but the glyphs to keep may be scattered. Remapping means re-arranging the kept glyphs consecutively in a new order: original GID 0 (.notdef) stays, original GID 1523 may become new GID 1, original GID 8944 becomes new GID 2, and so on.

After remapping, all tables referencing GIDs must be updated in sync: the glyf (or CFF) table keeps only the corresponding glyph data and reorders by new index; the loca table rebuilds position indices; the hmtx table rebuilds horizontal metrics; the post table updates PostScript name mappings. Mishandling here corrupts the font, so strict adherence to the OpenType spec is required.

Step Operation Principle Data Tables Processed
1. Character usage scan Traverse all PDF page content streams, extract displayed character encodings Collect Unicode code points by parsing text operators (Tj/TJ) None (generates character set)
2. CMap table rebuild Rebuild encoding-to-glyph-index mapping based on used characters Keep only used character mapping entries, delete the rest cmap
3. Glyph index remapping Re-arrange used glyphs consecutively, update all referencing indices Original indices may be non-consecutive; after reordering, indices 0 to N are consecutive glyf/CFF, loca, hmtx

3. Test Data: Three Fonts Before and After Subsetting

We selected three common fonts for subsetting tests, representing Chinese fonts (Source Han Serif, Microsoft YaHei) and an English font (Arial). The test document was a 50-page Chinese bid, using 1342 characters.

Test data shows Chinese font subsetting is most dramatic — Source Han Serif dropped from 18.2MB to 0.42MB, a 97.7% reduction. This is because Chinese fonts have many glyphs (60K+) but documents use few (1000+), leaving huge trimming room. The English Arial was originally only 0.82MB, subsetting to 0.06MB — a 92.7% reduction; the absolute size is small but the ratio is equally notable.

Now subsetting effects at different character usage counts, using Source Han Serif:

CMap Subtable Format Encoding Range Use Subsetting Handling
Format 0 0–255 Single-byte ASCII/Latin Trim unused entries
Format 4 BMP basic plane Common CJK characters Rebuild segment table
Format 12 Full Unicode Covers all characters Trim unused segments

4. Subsetting Tools Comparison and Scenario Recommendations

Multiple tools are available for font subsetting, from open-source CLI tools to commercial compression engines, each with pros and cons. The table below compares mainstream options.

SmartSlim, built on its self-developed Rust compression engine, automatically handles both TrueType and OpenType CFF glyph formats during subsetting, supporting batch drag-and-drop of hundreds of PDFs. More importantly, the entire subsetting process happens locally — font data and document content never pass through any external server, which is critical for classified documents and enterprise-sensitive files.

Subsetting strategy recommendations by scenario:

For more PDF optimization tips, see PDF Linearization Optimization Guide and Word Document Compression Methods.

Font Original File Glyphs (Original) Glyphs (Subset) After Subsetting Reduction
Source Han Serif Regular 18.2MB 65535 1342 0.42MB 97.7%
Microsoft YaHei Regular 15.6MB 28622 1342 0.35MB 97.8%
Arial Regular 0.82MB 3257 96 0.06MB 92.7%

5. Frequently Asked Questions

Q1: Does PDF font subsetting affect display?

No. Font subsetting only discards characters and glyph data not used in the document; retained characters are identical to the original font, with zero display impact. The subsetted font remains vector outlines — scaling up or down does not distort, and attributes like color and weight are preserved. The only limitation is that the subsetted font can only be used in that document, not reused in others.

Q2: How much size can font subsetting reduce?

Depends on the ratio of character usage to original font size. Chinese fonts (e.g., Source Han Serif 18MB) typically use only 1000-2000 characters; after subsetting, size drops to 0.3-0.8MB, a 95%+ reduction. English fonts (e.g., Arial 0.8MB) use even fewer characters; after subsetting, 0.05-0.1MB, about 90% reduction. The larger the font and the fewer characters used, the more dramatic the subsetting effect.

Q3: Can text still be edited in a subsetted PDF?

With limitations. Subsetting retains only the characters the document already uses; if you edit and input a new character (one not in the original document), it cannot display — it will show as a box or blank. So subsetting suits final archival and distribution, not documents still needing extensive editing. If editing is needed, keep the full font or re-embed a subset.

Q4: How to check whether a PDF has already been font-subsetted?

Open the PDF in Adobe Acrobat, click File - Properties - Fonts, and view the embedded font list. If a font name has a six-character prefix (e.g., ABCDEO+Source Han Serif), it has been subsetted. You can also open the PDF in SmartSlim — the engine automatically analyzes font embedding status and prompts whether subsetting is needed, along with an estimated compressed size.

Document Type Characters Used Size After Subsetting Reduction Notes
Short notice (1 page) ~200 0.08MB 99.6% Few characters, tiny subset
Meeting minutes (10 pages) ~600 0.19MB 99.0% Daily office document
Bid (50 pages) ~1342 0.42MB 97.7% Professional doc, broad coverage
Technical manual (200 pages) ~2800 0.85MB 95.3% Large character usage
Encyclopedia (1000 pages) ~6500 1.92MB 89.5% Near-limit coverage

6. Summary

PDF font subsetting is one of the most effective ways to reduce PDF size, especially dramatic for documents with embedded Chinese fonts. The core principle is three steps: scan used characters, rebuild the CMap mapping table, and reorder glyph indices to discard unused glyphs. Test data shows Source Han Serif at 18MB subsetting to just 0.4MB — a 97.7% reduction — with zero display impact.

Practical advice: always do font subsetting before final distribution, and use a local tool for classified documents. If you need to batch-process PDFs, SmartSlim supports 10 categories and 40+ formats including PDF/images/video/Office/OFD, with its self-developed Rust compression engine automatically performing font subsetting — data stays on-prem.

FAQ

Q: What is PDF font subsetting?
A: Font subsetting is the process of extracting only the characters actually used in a document from a font file, discarding the rest. For example, a Chinese font like Source Han Serif is 18MB complete, but a typical document uses only 500-2000 characters. After subsetting, the font data is reduced to 0.3-0.5MB — a 97%+ reduction. The subsetted font displays identically to the original because all used characters are preserved with their original glyphs.

Q: How does font subsetting reduce file size by 90%?
A: Full Chinese fonts contain 20,000+ characters (GB2312: 6763, GB18030: 27,533, Big5: 13,060). A typical document uses only 500-2000 unique characters (3-10% of the total). Font subsetting removes unused characters, their glyph outlines, and associated metric data. The CMap table is rebuilt to include only the used characters. Result: a 16.8MB Source Han Serif font is subsetted to 0.32MB — a 98.1% reduction.

Q: Is font subsetting compatible with all PDF readers?
A: Yes. Font subsetting is a standard feature of the PDF specification (ISO 32000). All PDF readers properly handle subsetted fonts because the PDF file contains all the necessary font data for the used characters. The only difference is that the font's internal name is prefixed with a 6-character tag (e.g., 'ABCDEF+SourceHanSerif') to indicate it's a subset. SmartSlim performs font subsetting in compliance with the PDF standard.

Q: Can I subset fonts from any PDF file?
A: Font subsetting works on PDFs that contain embedded fonts. PDFs with non-embedded fonts (using system fonts) don't need subsetting — they reference system fonts directly. PDF/A (archival) documents always embed fonts and benefit greatly from subsetting. SmartSlim automatically detects embedded fonts in PDFs and applies subsetting, reducing font-related size by 90-98%.

Summary

The key to pdf font subsetting principle: why... lies in identifying the sources of bloat and handling them accordingly. Choose the right compression strategy based on your scenario, prioritizing the largest contributors. SmartSlim can handle all compression steps in one click.

Related:

Top comments (0)