Have you ever opened a PDF where the text looks perfect, but when you copy and paste a sentence, it turns into gibberish symbols? Or wondered why a 1-page document with three fonts is 5MB? In this deep dive, we explore how PDFs store and manage typography.
Supported PDF Font Types
PDF supports several font representations: Type 1 (PostScript), TrueType (/TrueType), OpenType/CFF (Compact Font Format, /Type1C), Type 3 (user-defined vector paths), and Type 0 (Composite CIDFonts for international UTF-8 scripts).
Anatomy of a PDF Font Dictionary
A font is represented by a dictionary referencing glyph dimensions and outline streams:
22 0 obj
<<
/Type /Font
/Subtype /TrueType
/BaseFont /BAAAAA+Inter-Bold
/FirstChar 32
/LastChar 122
/Widths [ 250 0 0 0 0 0 0 0 ... ]
/FontDescriptor 23 0 R
/ToUnicode 24 0 R
>>
endobj
The ToUnicode CMap (Why Copy/Paste Works)
PDF rendering engines draw glyphs using internal character codes (e.g. index 14). To allow text selection, copying, and search indexing, the PDF embeds a ToUnicode CMap table mapping internal glyph indexes back to standard UTF-16 Unicode character codes.
Frequently Asked Questions
Why does copying text from some PDFs result in weird symbols?
Because the creator software subsetted the font with custom character codes but failed to embed a valid ToUnicode CMap translation table.