Every kind of font dictionary, the font programs that can be embedded for each, and how a font turns character codes into glyphs.
Type1, MMType1, Type3 and TrueType date from PDF 1.0, and PDF 1.2 added composite fonts: Type0 and its two CIDFont types. Later versions added ways to embed fonts (TrueType in 1.1, CFF in 1.2 and 1.3,
OpenType in 1.6) but no subtypes, and PDF 2.0 says no other /Subtype values are valid.
A font is a dictionary with /Type /Font. A page lists it under a name in its /Resources /Font, and a content stream selects it with Tf. The /Subtype decides how the bytes of a shown string become glyphs. In a simple font each byte is one character code, so at most 256 glyphs are in reach at once. In a composite (Type 0) font a CMap reads codes of one or more bytes. Except for Type 3, the font dictionary only describes the font: the glyph shapes are in a separate font program, embedded in the file or found on the reader’s system. The Text and fonts page in Learning shows how the pieces fit together.
Font subtypes
| Subtype | Glyphs and entries | Added |
|---|---|---|
/Type0composite font | Glyphs. None of its own. It pairs a CMap, which turns the bytes of a string into CIDs, with one CIDFont that holds the glyphs. Codes can be one or more bytes long, so a font can reach thousands of glyphs. Entries. | |
/Type1simple font | Glyphs. A Type 1 font program: PostScript-style outlines with hints. Embedded with Entries. | |
/MMType1simple font | Glyphs. One instance of a multiple master font, a Type 1 font with design axes such as weight and width. If it is embedded, the program is an ordinary Type 1 font for that instance, not the multiple master font itself. Entries. The same as | |
/Type3simple font | Glyphs. Content streams in the font dictionary itself. Entries. | |
/TrueTypesimple font | Glyphs. A TrueType font program, embedded with Entries. The same as | |
/CIDFontType0descendant CIDFont | Glyphs. Type 1-style outlines in CFF, looked up by CID. Embedded with Entries. | |
/CIDFontType2descendant CIDFont | Glyphs. A TrueType program, which numbers its glyphs by glyph index rather than CID. Embedded with Entries. The same as |
Every font dictionary also has /Type /Font, and before PDF 1.1 a /Name matching its resource name. Acrobat ignores /Name, and PDF 2.0 deprecates it. The font descriptor is always an indirect object and the widths array usually is, as in this embedded TrueType font, a subset holding only the glyphs the document uses:
7 0 obj << /Type /Font /Subtype /TrueType /BaseFont /KLMNOP+ExampleSans /FirstChar 32 /LastChar 126 /Widths 8 0 R % 95 widths, codes 32 to 126 /Encoding /WinAnsiEncoding /FontDescriptor 9 0 R >> endobj 9 0 obj << /Type /FontDescriptor /FontName /KLMNOP+ExampleSans /Flags 32 % Nonsymbolic /FontBBox [-160 -230 1120 940] /ItalicAngle 0 /Ascent 900 /Descent -220 /CapHeight 700 /StemV 80 /FontFile2 10 0 R >> endobj 10 0 obj << /Length 11 0 R /Length1 21844 % the TrueType program's length once decoded /Filter /FlateDecode >> stream …compressed TrueType data… endstream endobj
Embedded font programs
An embedded font program is a stream, the font file, referenced from the font descriptor. The key that holds it, and for /FontFile3 the stream’s own /Subtype, say what format it is. A font descriptor has at most one of the three keys. Type 3 fonts have nothing to embed, and a Type 0 font’s program belongs to its CIDFont.
| Font file | What it holds, and for which fonts | Added |
|---|---|---|
/FontFile | A Type 1 font program in its original form: a clear-text part, an encrypted part (binary only in PDF) and a fixed part of 512 zeros and | |
/FontFile2 | A TrueType font program. A simple font’s program needs a For | |
/FontFile3/Subtype /Type1C | A Type 1-equivalent font in the Compact Font Format (CFF). Exactly one font per stream. | |
/FontFile3/Subtype /CIDFontType0C | A CIDFont in the Compact Font Format. For | |
/FontFile3/Subtype /OpenType | An OpenType font program. Which font dictionary it can serve depends on its outlines: TrueType outlines (a For |
Besides /Length and /Filter, the font file’s stream dictionary has:
/Length1,/Length2,/Length3: for a Type 1 program, the byte lengths of its clear-text, encrypted and fixed parts after decoding; for TrueType,/Length1alone is the whole program. A/Length3of 0 means the 512 zeros andcleartomarkwere left out and the reader adds them. CFF programs have none of the three./Subtype(PDF 1.2), required in a/FontFile3stream./Metadata(PDF 1.4), an optional XMP metadata stream about the font.
Whether glyphs are filled or stroked is up to the text rendering mode (Tr); a Type 1 program’s own PaintType is ignored. Vertical metrics come only from a CIDFont’s /DW2 and /W2; a TrueType program’s vhea and vmtx tables are never used. Font licenses can forbid embedding, and unless told otherwise a reader may use an embedded program only to view and print that document.
Subsets
Since PDF 1.1 an embedded font can be a subset holding only the glyphs a document uses. Its /BaseFont and /FontName start with a tag of exactly six uppercase letters and a plus sign, as in /KLMNOP+ExampleSans; two different subsets in one file need different tags. A descriptor may also list what the subset holds, with /CharSet for Type 1 or /CIDSet for CIDFonts, but the tag is often the only sign. PDF 2.0 deprecates both entries.
Encodings for simple fonts
A simple font maps each byte, 0 to 255, to a glyph: that mapping is its encoding. Every font program except Type 3 has a built-in encoding. The font dictionary’s /Encoding can replace it with one of three predefined encodings, named directly, or change it with an encoding dictionary.
| Encoding | What it is |
|---|---|
WinAnsiEncodingpredefined name | Windows code page 1252, the usual Windows encoding for Western Latin text. The common choice for Latin text with Type 1 and TrueType fonts. |
MacRomanEncodingpredefined name | The classic Mac OS encoding for Western Latin text. Usable with Type 1 and TrueType fonts. The Mac OS Roman encoding used by a TrueType font’s (1, 0) cmap subtable is not quite the same: it has 15 more characters, and the Euro sign where this one has currency. |
MacExpertEncodingpredefined name | For “expert” fonts, which add small capitals, fractions, ligatures and similar characters. Not tied to the Mac despite its name. None of the standard 14 fonts has the expert character set. |
StandardEncodingnot a value of /Encoding | Adobe’s standard Latin encoding, the built-in encoding of Latin-text Type 1 fonts such as Times, Helvetica and Courier. It isn’t a predefined encoding in PDF, so it can’t be named in /Encoding; a font gets it as its built-in encoding, or as the implicit base of a /Differences array. It lacks accented letters such as é and ü, and code 39 is quoteright, not the ASCII apostrophe. |
| Built-in encodingnot a value of /Encoding | The font program’s own code-to-glyph mapping, used when the font dictionary has no /Encoding. For a Type 1 font it is the Encoding array in the program; for TrueType it is the cmap table. Symbolic fonts such as Symbol and ZapfDingbats rely on it. Type 3 fonts have none. |
PDFDocEncodingnot a value of /Encoding | Not a font encoding. It is the single-byte encoding for text strings outside content streams, such as bookmark titles and the document information dictionary; the alternative is UTF-16BE, and from PDF 2.0 also UTF-8. Fonts don’t use it. |
Encoding dictionaries and Differences
An encoding dictionary starts from a base encoding and lists changes in a /Differences array. Each number in the array is a character code; the glyph names after it are assigned to that code and the codes that follow, until the next number. Ranges may come in any order but must not overlap.
<< /Type /Encoding
/BaseEncoding /WinAnsiEncoding
/Differences [ 1 /fi /fl /ff % codes 1, 2 and 3
31 /dotlessi ] % code 31
>>- Without
/BaseEncoding, the base is the font program’s built-in encoding if the font is embedded. If it isn’t, the base isStandardEncodingfor a nonsymbolic font and the built-in encoding for a symbolic one, as the font descriptor’s flags say. - Type 1: a name can be any glyph in the program. A name the program lacks shows its
.notdefglyph. - Type 3: there is no built-in encoding, so
/Encodingis required and its/Differenceslists every code the font uses, naming keys of/CharProcs. - TrueType:
/Differencesshould not be used. See below.
TrueType encodings
A TrueType program’s built-in encoding is its cmap table, whose subtables, each identified by a platform and encoding pair such as (3, 1), map codes straight to glyphs. The rules since PDF 1.3:
- With
/WinAnsiEncodingor/MacRomanEncoding, or the Nonsymbolic flag: code → glyph name, then through the (3, 1) Unicode subtable via the Adobe Glyph List, or else through the (1, 0) Mac Roman subtable. The program’sposttable is the fallback. - With no
/Encoding, or the Symbolic flag: the byte goes straight into the (3, 0) subtable, with a high byte such asF0added, or else into the (1, 0) subtable.
Anything else is up to the reader, so a TrueType font should be embedded, a nonsymbolic one should use /WinAnsiEncoding or /MacRomanEncoding with no differences, and a symbolic one should have no /Encoding. To reach glyphs no encoding names, use a Type 0 font instead.
Composite fonts
A Type 0 font has no glyphs of its own. Its /Encoding is a CMap that decodes the string into CIDs (character identifiers), and its only descendant, a CIDFont, finds a glyph for each CID. They were made for large character sets such as Chinese, Japanese and Korean, and they are how a PDF reaches more than 256 glyphs of one font.
CMaps
- Predefined CMaps are given by name. Most are for CJK encodings, such as
/90ms-RKSJ-H(Windows code page 932, Japanese) or/UniGB-UCS2-H(Unicode for simplified Chinese). A name ending inHis for horizontal writing,Vfor vertical. /Identity-Hand/Identity-Vread every code as two bytes, high byte first, and use the number as the CID. They work with any CIDFont. ISO 32000-1 forbids them with a font that isn’t embedded.- Embedded CMaps are streams with
/Type /CMap,/CMapName,/CIDSystemInfo, optional/WMode(0 horizontal, 1 vertical) and optional/UseCMapto build on another CMap. The data is in Adobe’s CMap file format: codespace ranges set how many bytes each code takes, andcidcharandcidrangesections map codes to CIDs.
CIDSystemInfo
A CID means something only within a character collection, named by a CIDSystemInfo dictionary: /Registry and /Ordering strings and a /Supplement number, such as (Adobe), (Japan1) and 4. A CMap and the CIDFont it is used with must agree on registry and ordering; supplements only add CIDs. The Identity CMaps belong to the collection Adobe-Identity-0, and fonts used with them often give (Adobe) (Identity) 0 as well.
CIDToGIDMap and widths
A TrueType program numbers its glyphs by glyph index (GID), not CID. So an embedded CIDFontType2 has a /CIDToGIDMap: /Identity if CID and GID are the same, or a stream of 2-byte GIDs, one per CID starting from CID 0. With /Identity-H and /CIDToGIDMap /Identity, the bytes in a string are simply glyph indices.
CIDFont widths are in /DW, the default (1000 if absent), and /W, which mixes two forms: a CID followed by an array of widths for consecutive CIDs, or a first and last CID followed by one width for the range. /W [3 [250] 17 [722 444] 36 39 500] gives CID 3 a width of 250, CIDs 17 and 18 widths of 722 and 444, and CIDs 36 to 39 a width of 500. Every CIDFont must have a glyph for CID 0, used for codes that map to nothing.
A Type 0 font with an embedded TrueType subset, the usual way to embed fonts with many glyphs:
11 0 obj << /Type /Font /Subtype /Type0 /BaseFont /QRSTUV+ExampleSerif /Encoding /Identity-H % 2-byte codes, code = CID /DescendantFonts [12 0 R] /ToUnicode 15 0 R >> endobj 12 0 obj << /Type /Font /Subtype /CIDFontType2 /BaseFont /QRSTUV+ExampleSerif /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /FontDescriptor 13 0 R % with /FontFile2 14 0 R /DW 1000 /W [3 [250] 17 [722 444]] /CIDToGIDMap /Identity % CID = glyph index >> endobj
A content stream shows text with it two bytes per glyph: /F2 12 Tf <00110012> Tj draws glyphs 17 and 18. Nothing in those bytes says which characters they are, which is what /ToUnicode is for. The Type 0 font’s /BaseFont is conventionally the CIDFont’s name, with - and the CMap name added when the CIDFont is a CIDFontType0.
ToUnicode and text extraction
Character codes say which glyph to draw, not which character it stands for. To copy, search or extract text, a reader needs Unicode values, and ISO 32000-1 gives the order to try them in:
- The font’s
/ToUnicodeCMap, if it has one. - For a simple font using
WinAnsiEncoding,MacRomanEncodingorMacExpertEncoding, or differences that use only standard Latin and Symbol glyph names: code → glyph name → Unicode, through the Adobe Glyph List. - For a composite font with a predefined CMap other than Identity, or an Adobe-GB1, -CNS1, -Japan1 or -Korea1 collection: code → CID → Unicode, through Adobe’s CMap for that collection, such as Adobe-Japan1-UCS2.
When all three fail, the glyphs still show, but copied text comes out as nonsense or nothing. The common case is an embedded subset with /Identity-H: its codes are glyph indices that mean nothing outside that font program. Simple fonts with made-up glyph names have the same problem. A structure element or marked-content sequence can also give its text directly, in /ActualText.
A ToUnicode CMap (PDF 1.2) is a stream in CMap syntax. Its codespace must match the font’s codes, one byte for a simple font. bfchar and bfrange sections map codes to UTF-16BE, and one code may stand for several characters, as a ligature does. For the Type 0 font above:
15 0 obj << /Length 16 0 R >> stream /CIDInit /ProcSet findresource begin 12 dict begin begincmap /CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def /CMapName /Adobe-Identity-UCS def /CMapType 2 def 1 begincodespacerange <0000> <FFFF> endcodespacerange 3 beginbfchar <0003> <0020> % glyph 3: space <0011> <0048> % glyph 17: H <0059> <00660069> % glyph 89: the fi ligature, two characters endbfchar 1 beginbfrange <0012> <0014> <0069> % glyphs 18 to 20: i, j, k endbfrange endcmap CMapName currentdict /CMap defineresource pop end end endstream endobj
Font descriptors
A font descriptor holds font-wide metrics and the embedded program. A reader without the font program uses the metrics to pick or fake a similar font. Simple fonts and CIDFonts have one (before PDF 2.0, the standard 14 fonts could do without); Type 0 fonts never do, and Type 3 fonts may from PDF 1.5. It is an indirect object with /Type /FontDescriptor. Values are in glyph space, which for every font type but Type 3 is a thousandth of a text space unit. Requirements are as in ISO 32000-1; the PDF 1.4 reference requires the same entries without the Type 3 exceptions.
| Entry | What it holds |
|---|---|
FontNameRequired | The PostScript name, the same as the font dictionary’s /BaseFont, subset tag included. |
FlagsRequired | A 32-bit set of flags: fixed pitch, serif, symbolic, italic and so on. |
FontBBoxRequired, except for Type 3 | The smallest box that would enclose every glyph drawn at the same origin, in glyph space. |
ItalicAngleRequired | The slant of vertical strokes in degrees counterclockwise from vertical: 0 for upright, negative for fonts that lean right, such as -12. |
AscentRequired, except for Type 3 | The highest point of the glyphs above the baseline, not counting accents. |
DescentRequired, except for Type 3 | The lowest point below the baseline, as a negative number. |
CapHeightRequired for fonts with Latin characters, except for Type 3 | The height of flat capital letters such as H. |
StemVRequired, except for Type 3 | The thickness of the dominant vertical stems: how heavy the font is, which a substitute font can imitate. |
XHeight, StemH, LeadingOptional | The height of flat lowercase letters such as x, the thickness of horizontal stems, and the preferred spacing between baselines. Each defaults to 0. |
AvgWidth, MaxWidthOptional | The average and largest glyph widths. Default 0. |
MissingWidthOptional | The width for codes outside the font dictionary’s /FirstChar to /LastChar range. Default 0. |
FontFile, FontFile2, FontFile3Optional; at most one | The embedded font program. FontFile2 came in PDF 1.1 and FontFile3 in PDF 1.2. |
CharSetOptional | For a Type 1 subset, the glyph names it contains, as a string such as (/A/B/C). |
FontFamily, FontStretch, FontWeightOptional | The family name as a string, the width as a name from /UltraCondensed to /UltraExpanded, and the weight from 100 to 900, where 400 is normal and 700 bold. ISO 32000-1 asks for them in Type 3 fonts of Tagged PDF documents. |
A CIDFont’s descriptor may add:
| Entry | What it holds |
|---|---|
StyleOptional | A dictionary whose /Panose string classifies the design. |
LangOptional | The font’s language, for encodings that don’t imply one. ISO 32000-1 marks it PDF 1.5, though the PDF 1.4 reference already lists it. |
FDOptional | Metrics that override the main descriptor for classes of glyphs, such as proportional Latin glyphs in a Japanese font. |
CIDSetOptional | For a subset, a bit table with one bit per CID: set if the glyph is present. |
Flags
/Flags is an unsigned 32-bit integer. Bits are numbered from 1, the lowest; each flag adds its value. Unlisted bits are reserved and must be 0. A serif italic Latin font, for example, has Serif, Nonsymbolic and Italic set: 2 + 32 + 64 = /Flags 98.
| Bit | Value | Name | Meaning |
|---|---|---|---|
| 1 | 1 | FixedPitch | Every glyph has the same width. |
| 2 | 2 | Serif | Glyphs have serifs. |
| 3 | 4 | Symbolic | The font has glyphs outside the Adobe standard Latin character set. Exactly one of Symbolic and Nonsymbolic must be set. |
| 4 | 8 | Script | Glyphs look like cursive handwriting. |
| 6 | 32 | Nonsymbolic | The font uses only the Adobe standard Latin character set, or part of it, with the standard glyph names. |
| 7 | 64 | Italic | The dominant vertical strokes are slanted. |
| 17 | 65536 | AllCap | No lowercase letters, as in fonts for titles. |
| 18 | 131072 | SmallCap | The lowercase letters are small capitals. |
| 19 | 262144 | ForceBold | Bold glyphs may be drawn thicker at small sizes on low-resolution screens, so they still look bold. |
Symbolic and Nonsymbolic are one choice spread over two bits. To PDF, a font is symbolic if it has any glyph outside the Adobe standard Latin character set, even an extra Latin letter. The choice sets the implicit base encoding and can steer font substitution.
What PDF 2.0 changed
- No new subtypes, and no other
/Subtypevalues are valid. There is still no OpenType font subtype: an OpenType program goes in/FontFile3with/Subtype /OpenTypeunder aTrueType,Type1,CIDFontType0orCIDFontType2font. TheTrueTypesubtype now explicitly covers OpenType font programs too. - Widths and font descriptors for every Type 1 font.
/FirstChar,/LastChar,/Widthsand/FontDescriptorare required, the standard 14 fonts included; readers still supply the metrics for older files that leave them out. - Embed fonts. Font programs should be embedded, except for text in rendering mode 3 (invisible), where embedding is optional.
- Deprecated:
/Namein font dictionaries,/CharSetand/CIDSetin font descriptors, and the Adobe-Japan2 and Adobe-Korea1 character collections. Adobe-KR is new. - Tighter rules: the CIDFont table lists
/CIDToGIDMapas required for an embeddedCIDFontType2, with no default (ISO 32000-1’s table called it optional, default/Identity, though its text already required it); a subset’s name must be the tag,+and the original PostScript name, and the subset must include.notdef.
Checked against §5.4–5.9 and Appendix D of the Adobe PDF Reference, third edition (PDF 1.4, Tables 5.7–5.23 and D.1), §9.5–9.10 and Annex D of ISO 32000-1:2008 (PDF 1.7, Tables 110–127 and D.1), and §9.5–9.10 of ISO 32000-2:2020 (PDF 2.0). The PDF 1.0 manual confirms which subtypes and font file keys date from PDF 1.0.