Text in a PDF is drawn with fonts named in the page’s resources. A font dictionary says what kind of font it is, how the bytes of a string map to glyphs, how wide each glyph is, and where the font program is, if it is embedded. Most PDFs embed their fonts, often only the glyphs they use. The text a reader extracts comes from the font’s encoding or its ToUnicode map, not from the glyphs.
Font types
Subtype | Since | Codes | Font program |
|---|---|---|---|
Type1 | 1.0 | one byte | Type 1 (PostScript) in FontFile, or Compact Font Format in FontFile3 Type1C, or OpenType in FontFile3 OpenType |
MMType1 | 1.0 | one byte | A Multiple Master instance; as Type 1 |
TrueType | 1.1 | one byte | TrueType in FontFile2, or OpenType in FontFile3 |
Type3 | 1.0 | one byte | Glyphs drawn by content streams in the font dictionary itself |
Type0 | 1.2 | one to four bytes, by a CMap | A composite font: one CIDFont below it |
CIDFontType0 | 1.2 | CIDs | CFF CIDFont in FontFile3 CIDFontType0C (1.3), or OpenType |
CIDFontType2 | 1.2 | CIDs | TrueType in FontFile2, or OpenType |
Every font dictionary has Type Font. CIDFontType0 and
CIDFontType2 are never used directly: a Type 0 font refers to them.
Simple fonts: Type 1 and TrueType
A simple font has at most 256 glyphs, one for each byte of a string.
| Key | Since | Meaning |
|---|---|---|
Type, Subtype | 1.0 | Font, and Type1, MMType1 or TrueType |
Name | 1.0 | The resource name; required only in PDF 1.0, 2.0 deprecated |
BaseFont | 1.0 | Required. The PostScript name of the font, such as Helvetica-Bold or ABCDEF+Garamond |
FirstChar, LastChar | 1.0 | The first and last codes in Widths |
Widths | 1.0 | The width of each code from FirstChar to LastChar, in thousandths of a text space unit |
FontDescriptor | 1.0 | The font descriptor |
Encoding | 1.0 | A base encoding name or an encoding dictionary |
ToUnicode | 1.2 | A CMap from codes to Unicode |
Up to PDF 1.7, FirstChar, LastChar, Widths and
FontDescriptor are required except for the
standard 14 fonts. In PDF 2.0 they are required for every
simple font except Type 3’s descriptor.
TrueType
A TrueType font, from PDF 1.1, has the same keys as Type 1, with the font program in
FontFile2. How a byte code finds a glyph depends on the font’s
cmap tables and the flags. For a non-symbolic font the code is mapped
through the encoding to a glyph name, then to Unicode, and looked up in the (3, 1)
Microsoft Unicode cmap, or through the name in the (1, 0) Macintosh
cmap. For a symbolic font the code is looked up directly in the (3, 0)
symbol cmap, often at 0xF000 plus the code, or in (1, 0). Readers differ
in the details, which is why writers usually embed TrueType fonts as CIDFontType2 with
Identity mapping instead.
Type 3 fonts
A Type 3 font’s glyphs are content streams. Its keys:
| Key | Since | Meaning |
|---|---|---|
FontBBox | 1.0 | Required. The bounding box of all glyphs, in glyph space |
FontMatrix | 1.0 | Required. Glyph space to text space, often [0.001 0 0 0.001 0 0] |
CharProcs | 1.0 | Required. Glyph names to content streams, each starting with d0 or d1 |
Encoding | 1.0 | Required. An encoding dictionary with Differences: codes to glyph names |
FirstChar, LastChar, Widths | 1.0 | Required. Widths in glyph space |
FontDescriptor | 1.0 | Required in tagged PDF |
Resources | 1.2 | The resources the glyph procedures use |
ToUnicode | 1.2 | Codes to Unicode |
Type 3 fonts hold bitmap fonts from TeX and similar systems, and shapes that are not outline fonts.
Type 0 (composite) fonts
A Type 0 font, from PDF 1.2, has many glyphs and multi-byte codes, for Chinese, Japanese and Korean, and for any font embedded with more than 256 glyphs.
| Key | Meaning |
|---|---|
BaseFont | Required. The name, usually the CIDFont’s name, with the CMap’s name joined by a hyphen when it is predefined |
Encoding | Required. A CMap: a predefined CMap’s name, such as Identity-H, or an embedded CMap stream. It turns the bytes of a string into codes and the codes into CIDs |
DescendantFonts | Required. An array of one CIDFont |
ToUnicode | Codes to Unicode |
CIDFonts
A CIDFont is a font whose glyphs are numbered by CID, a character identifier. It is the one font below a Type 0 font.
| Key | Meaning |
|---|---|
Subtype | CIDFontType0 (CFF glyphs) or CIDFontType2 (TrueType glyphs) |
BaseFont | Required. The font’s PostScript name |
CIDSystemInfo | Required. Registry, Ordering and Supplement, the character collection: (Adobe) (Japan1) 6, or (Adobe) (Identity) 0 |
FontDescriptor | Required. The font descriptor |
DW, W | The default and individual widths |
DW2, W2 | Vertical metrics, for vertical writing |
CIDToGIDMap | Type 2 only: Identity (CID equals glyph index) or a stream of two-byte glyph indices, one per CID |
The usual way to embed any OpenType or TrueType font today: a Type 0 font with
Encoding Identity-H, a CIDFontType2 with
CIDToGIDMap Identity, two-byte codes in strings that are the glyph
indices, and a ToUnicode CMap so that the text can be copied.
The standard 14 fonts
Fourteen Type 1 fonts may be used by name without being embedded:
Times-Roman, Times-Bold, Times-Italic,
Times-BoldItalic, Helvetica, Helvetica-Bold,
Helvetica-Oblique, Helvetica-BoldOblique,
Courier, Courier-Bold, Courier-Oblique,
Courier-BoldOblique, Symbol and ZapfDingbats.
Readers draw them with fonts of the same metrics, such as Nimbus or Liberation. For
any other font left out, a reader substitutes a font with the flags and widths of the
descriptor. PDF/A and PDF/X require every font to be embedded, the standard 14
included.
Encodings
A simple font’s Encoding maps one-byte codes to glyph names, which the
font program then finds. It is a name, or a dictionary:
StandardEncoding– Adobe’s standard Latin encoding, the built-in encoding of most Type 1 fonts; used when nothing else is given for a non-symbolic fontMacRomanEncoding– the classic Mac OS character setWinAnsiEncoding– Windows code page 1252MacExpertEncoding– expert glyphs: small capitals, fractions, old-style figures- An encoding dictionary –
Type Encoding,BaseEncoding(one of the names above) andDifferences, an array such as[39 /quotesingle 96 /grave 128 /Adieresis /Aring]: a code, then the names of that code and the codes after it
A symbolic font with no Encoding, such as Symbol or
ZapfDingbats, uses the encoding built into its font program. PDFDocEncoding
is for text strings only, never for fonts.
CMaps
A CMap, from PDF 1.2, maps the bytes of a string to codes and the codes to CIDs, for a
Type 0 font. It decides how many bytes each code has, from its code space ranges. Two
CMaps work with any CIDFont: Identity-H and Identity-V,
two-byte codes that equal the CID, horizontal and vertical. Many others are predefined
for each Asian character collection, such as:
| Collection | Some predefined CMaps |
|---|---|
| Adobe-GB1 (simplified Chinese) | GB-EUC-H, GBK-EUC-H, UniGB-UCS2-H, UniGB-UTF16-H |
| Adobe-CNS1 (traditional Chinese) | B5pc-H, ETen-B5-H, UniCNS-UCS2-H, UniCNS-UTF16-H |
| Adobe-Japan1 | 83pv-RKSJ-H, 90ms-RKSJ-H, UniJIS-UCS2-H, UniJIS-UTF16-H |
| Adobe-Korea1 | KSCms-UHC-H, UniKS-UCS2-H, UniKS-UTF16-H |
The UTF-16 CMaps came with PDF 1.5. Each has a -V form for vertical
writing. An embedded CMap is a stream with Type CMap,
CMapName, CIDSystemInfo, WMode (0 horizontal,
1 vertical) and UseCMap, whose data is a CMap program in PostScript
syntax.
ToUnicode
A ToUnicode stream, from PDF 1.2, maps a font’s codes to Unicode, so that
text can be searched, copied and read aloud. It is a CMap program:
/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
2 beginbfchar
<0003> <0020>
<0024> <0041>
endbfchar
1 beginbfrange
<0044> <005D> <0061>
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
bfchar maps single codes; bfrange maps a run, either to
consecutive Unicode values or to an array of strings. A destination may be several
UTF-16BE units, for a ligature such as “fi” or a character outside the Basic
Multilingual Plane. Without a ToUnicode, a reader works from the
encoding’s glyph names (/Adieresis is Ä) or from a predefined CMap’s
collection.
The font descriptor
| Key | Since | Meaning |
|---|---|---|
Type | 1.0 | Required. FontDescriptor |
FontName | 1.0 | Required. The same as BaseFont |
FontFamily | 1.5 | The family name, such as (Times) |
FontStretch | 1.5 | UltraCondensed to UltraExpanded, Normal in the middle |
FontWeight | 1.5 | 100 to 900; 400 normal, 700 bold |
Flags | 1.0 | Required. The flags |
FontBBox | 1.0 | The bounding box of all glyphs, in glyph space; required except for Type 3 |
ItalicAngle | 1.0 | Required. Degrees anticlockwise from vertical, negative for a font that leans right |
Ascent, Descent | 1.0 | Height above and depth below the baseline; required except for Type 3 |
Leading | 1.0 | Line spacing; default 0 |
CapHeight | 1.0 | Height of capitals; required for Latin fonts except Type 3 |
XHeight | 1.0 | Height of lower-case letters; default 0 |
StemV, StemH | 1.0 | Thickness of vertical and horizontal stems; StemV required except for Type 3 |
AvgWidth, MaxWidth, MissingWidth | 1.0 | Average and largest widths, and the width for codes not in Widths; default 0 |
FontFile | 1.0 | An embedded Type 1 font program |
FontFile2 | 1.1 | An embedded TrueType font program |
FontFile3 | 1.2 | An embedded font program of the type given by its Subtype |
CharSet | 1.1 | For a Type 1 subset: the glyph names it holds, as (/A/B/C). 2.0 deprecated |
Style | 1.2 | CIDFonts: a Panose classification |
Lang | 1.5 | CIDFonts: the language |
FD | 1.2 | CIDFonts: descriptors that override this one for classes of glyphs |
CIDSet | 1.2 | CIDFonts: a stream with one bit for each CID in an embedded subset. 2.0 deprecated |
At most one of FontFile, FontFile2 and
FontFile3 may be present.
Flags
| Bit | Name | Meaning |
|---|---|---|
| 1 | FixedPitch | Every glyph is the same width |
| 2 | Serif | The glyphs have serifs |
| 3 | Symbolic | The font has glyphs outside the standard Latin set |
| 4 | Script | The glyphs look like handwriting |
| 6 | Nonsymbolic | The font uses the standard Latin set; exactly one of bits 3 and 6 should be set |
| 7 | Italic | The glyphs slant |
| 17 | AllCap | No lower-case letters |
| 18 | SmallCap | Lower-case letters are small capitals |
| 19 | ForceBold | Draw thin stems bold at small sizes |
Bit 1 is the lowest bit, value 1; so /Flags 32 is Nonsymbolic and
/Flags 4 Symbolic. Other bits are reserved and 0.
Embedded font programs
| Stream | Subtype | Since | Holds |
|---|---|---|---|
FontFile | – | 1.0 | A Type 1 font program, with Length1 (the clear-text part), Length2 (the encrypted part) and Length3 (the fixed-content part, 512 zeros and cleartomark, often 0) |
FontFile2 | – | 1.1 | A TrueType font program, with Length1, its length after decoding |
FontFile3 | Type1C | 1.2 | A Type 1 font as Compact Font Format (CFF) |
CIDFontType0C | 1.3 | A CID-keyed CFF font | |
OpenType | 1.6 | An OpenType font, with TrueType or CFF outlines |
Each may also carry Metadata (1.4). An OpenType font in
FontFile3 can serve a TrueType, Type1,
CIDFontType0 or CIDFontType2 font dictionary, as long as its
outlines suit it. A font program embedded in a PDF is a file of its own format; see
Font file formats.
Subsets
A writer that embeds only the glyphs used gives the font a name of six capital
letters, a plus sign and the real name: EOODIA+Poetica. The tag differs
for each subset, so that two subsets of the same font in one file, or in files joined
together, are not taken for each other. A subset’s glyph numbering may differ from the
full font, so the subset cannot be replaced by the installed font.
Widths
Glyph widths come from the PDF, not the font program; a reader uses them to place
each glyph, even when it draws the glyph from another font. For a simple font
Widths gives one width a code. A CIDFont gives DW, the
default (1,000), and W, an array of two forms mixed:
/W [ 120 [400 325 500] 7080 8032 1000 ]
For vertical writing, DW2 (default [880 −1000]) and
W2 give the vertical origin and advance in the same two forms, with three
numbers a CID.