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, through a font descriptor, what the font looks like and where its embedded program is. The glyph shapes are either in the file, as an embedded Type 1 or TrueType program or as Type 3 drawings, or left to the reader to supply. PDF 1.0 had Type 1 and Type 3 fonts; 1.1 added TrueType, and 1.2 composite fonts for large character sets.
Kinds of font
| Subtype | Since | What it is | Codes |
|---|---|---|---|
Type1 | 1.0 | A PostScript Type 1 font, or a compact (CFF) form of one | one byte |
MMType1 | 1.0 | A Multiple Master instance of a Type 1 font | one byte |
TrueType | 1.1 | A TrueType font | one byte |
Type3 | 1.0 | Glyphs drawn by PDF content streams in the file | one byte |
Type0 | 1.2 | A composite font: a CMap and one CIDFont | one to four bytes, by the CMap |
CIDFontType0 | 1.2 | A CIDFont of Type 1 (CFF) glyphs, used only inside a Type 0 font | CIDs |
CIDFontType2 | 1.2 | A CIDFont of TrueType glyphs, used only inside a Type 0 font | CIDs |
Every font dictionary has /Type /Font and a Subtype. The
first four are simple fonts: a string’s bytes are codes 0 to 255, each one glyph.
Type 1 fonts
| Key | Since | Meaning |
|---|---|---|
Type | 1.0 | Required: Font |
Subtype | 1.0 | Required: Type1 (or MMType1, TrueType) |
Name | 1.0 | The font’s name in the resources; required in PDF 1.0, optional later |
BaseFont | 1.0 | Required: the PostScript name of the font, such as /Helvetica-Bold |
FirstChar, LastChar | 1.0 | The first and last codes in Widths; required except for the standard 14 fonts |
Widths | 1.0 | An array of LastChar − FirstChar + 1 widths, in thousandths of a text space unit (glyph space units of 1/1000) |
FontDescriptor | 1.0 | The font descriptor; required except for the standard 14 |
Encoding | 1.0 | The encoding: a name or an encoding dictionary |
ToUnicode | 1.2 | A CMap from codes to Unicode, for copying and searching text |
The widths in the PDF are the ones that count for placing glyphs, even if the
embedded font program says otherwise. A code outside FirstChar to
LastChar takes the descriptor’s MissingWidth, default 0.
7 0 obj
<< /Type /Font /Subtype /Type1 /BaseFont /ABCDEF+Minion-Regular
/FirstChar 32 /LastChar 126 /Widths 8 0 R
/Encoding /WinAnsiEncoding /FontDescriptor 9 0 R >>
endobj
TrueType fonts
From PDF 1.1. The dictionary has the same keys as a Type 1 font, with
/Subtype /TrueType. BaseFont is the PostScript name from
the font’s name table, or the name with spaces removed, and for a
style made by the system a suffix such as ,Bold or
,Italic.
To find a glyph for a code, a reader uses the font’s cmap table. For
a non-symbolic font with an encoding, the code is turned into a glyph name, the
name into Unicode, and the (3, 1) Microsoft Unicode subtable consulted, or the name
looked up in the (1, 0) Macintosh table. For a symbolic font the code is looked up
directly in the (3, 0) subtable, often at 0xF000 plus the code, or in the (1, 0)
table. The rules leave room for error, and readers differ on badly made fonts.
Type 3 fonts
A Type 3 font has no font program. Each glyph is a small content stream in the PDF itself, so it can draw anything, bitmaps included: TeX’s bitmap fonts often reach PDF this way.
| Key | Since | Meaning |
|---|---|---|
Subtype | 1.0 | Required: Type3 |
FontBBox | 1.0 | Required: the box that holds every glyph, in glyph space; all zeros if not known |
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 |
Encoding | 1.0 | Required: an encoding dictionary whose Differences map codes to the names in CharProcs |
FirstChar, LastChar, Widths | 1.0 | Required: widths in glyph space, mapped by FontMatrix |
Resources | 1.2 | Resources the glyph streams use; before 1.2 they used the page’s |
ToUnicode | 1.2 | Codes to Unicode |
Each glyph stream begins with d0 or d1; see
Content streams.
The standard 14 fonts
Every reader is expected to have these, so in PDF 1.0 to 1.4 they may be used
without embedding, and without Widths or a descriptor:
| Family | Fonts |
|---|---|
| Times | Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic |
| Helvetica | Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique |
| Courier | Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique |
| Symbol | Symbol |
| Dingbats | ZapfDingbats |
Readers draw them with their own copies or close substitutes, using the widths from Adobe’s font metrics files. Any other font that is not embedded is replaced by a reader’s guess from the descriptor, which is why the descriptor’s flags and metrics matter.
Encodings
A simple font’s encoding maps each code, 0 to 255, to a glyph name such as
A, eacute or quotedblleft. The font program
then finds the glyph by name. Encoding is a name or a dictionary:
| Encoding | Meaning |
|---|---|
| none | The font program’s own built-in encoding; for a symbolic font, the usual case |
StandardEncoding | Adobe’s standard Latin encoding, the default for Type 1 fonts |
MacRomanEncoding | The Mac OS standard encoding for Latin text |
WinAnsiEncoding | Windows code page 1252 |
MacExpertEncoding | For expert fonts: small capitals, old-style figures, fractions |
| a dictionary | BaseEncoding, one of the names above, and Differences, an array that changes some codes |
Differences is a list in which a number sets the next code and each
name after it takes one code in turn:
<< /Type /Encoding /BaseEncoding /WinAnsiEncoding
/Differences [ 39 /quotesingle 96 /grave 128 /Euro /bullet ] >>
A string such as (Hello) shown in this font is the codes 72, 101, 108,
108, 111. Text in PDFs is only as readable as its encoding: copying text works when
the glyph names are standard or a ToUnicode CMap is present.
Type 0 fonts
From PDF 1.2, for Chinese, Japanese and Korean text and any font with more than 256 glyphs. A Type 0 font joins a CMap, which turns the bytes of a string into character identifiers (CIDs), and a CIDFont, which holds the glyphs by CID.
| Key | Meaning |
|---|---|
Subtype | Required: Type0 |
BaseFont | Required: usually the CIDFont’s name and the CMap’s, joined by a hyphen |
Encoding | Required: a predefined CMap’s name or an embedded CMap stream |
DescendantFonts | Required: an array of exactly one CIDFont |
ToUnicode | Codes to Unicode |
CIDFonts
| Key | Meaning |
|---|---|
Subtype | Required: CIDFontType0 or CIDFontType2 |
BaseFont | Required: the font’s name |
CIDSystemInfo | Required: the character collection, a dictionary of Registry (such as (Adobe)), Ordering (such as (Japan1)) and Supplement |
FontDescriptor | Required |
DW | The default width; default 1000 |
W | The widths of individual CIDs |
DW2, W2 | Vertical metrics for vertical writing; DW2 default [880 −1000] |
CIDToGIDMap | For CIDFontType2 with an embedded font: Identity, or a stream of two bytes a CID giving the glyph index |
W mixes two forms: a CID and an array of widths for it and the CIDs
that follow, or a first CID, a last CID and one width for them all:
/W [ 120 [ 400 325 500 ] 7080 8032 1000 ]
CMaps
A CMap maps byte sequences to CIDs. It also defines the code space: which byte
sequences are one, two, three or four bytes long, so a reader can split a string
into codes. It is either one of Adobe’s predefined CMaps, named in
Encoding, or a stream in the file holding a CMap program, with
/Type /CMap, CMapName, CIDSystemInfo,
WMode (0 horizontal, 1 vertical) and UseCMap.
| CMap | Meaning |
|---|---|
Identity-H, Identity-V | Two-byte codes, each the CID itself, horizontal or vertical; the usual choice for embedded subset fonts |
90ms-RKSJ-H, UniJIS-UCS2-H … | Japanese: Shift-JIS, Unicode |
GB-EUC-H, UniGB-UCS2-H … | Simplified Chinese |
B5pc-H, UniCNS-UCS2-H … | Traditional Chinese |
KSC-EUC-H, UniKS-UCS2-H … | Korean |
Each predefined CMap ends in -H for horizontal or -V for
vertical writing. The list grew with each version; a reader needs Adobe’s CMap
files, published as open source, to use them.
ToUnicode
From PDF 1.2 a font can carry a ToUnicode stream: a CMap program that
maps its codes to Unicode, so that text can be copied, searched and read aloud. It
uses the bfchar and bfrange sections of a CMap, with
UTF-16BE destinations:
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
2 beginbfchar
<0003> <0020>
<0024> <0041>
endbfchar
1 beginbfrange
<0044> <0046> <0061>
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
A destination can be several code units, for ligatures: <0102>
<00660069> maps one glyph to “fi”. Without ToUnicode, a
reader falls back on glyph names and the font’s own tables, and may get text wrong.
Font descriptors
A font descriptor gives the metrics and style of a font, for substituting it when it is not embedded, and points at the embedded program when it is:
| Key | Since | Meaning |
|---|---|---|
Type | 1.0 | Required: FontDescriptor |
FontName | 1.0 | Required: the same as the font’s BaseFont |
Flags | 1.0 | Required: the style flags |
FontBBox | 1.0 | Required except for Type 3: the box of all glyphs, in glyph space |
ItalicAngle | 1.0 | Required: the slant of vertical strokes, in degrees anticlockwise; negative for most italics |
Ascent, Descent | 1.0 | Required except for Type 3: the height above and depth below the baseline |
Leading | 1.0 | Spacing between lines; default 0 |
CapHeight | 1.0 | The height of capital letters; required for Latin fonts |
XHeight | 1.0 | The height of lower-case x; default 0 |
StemV, StemH | 1.0 | The thickness of vertical and horizontal stems; StemV required except for Type 3 |
AvgWidth, MaxWidth | 1.0 | Average and largest glyph width; default 0 |
MissingWidth | 1.0 | The width for codes not in Widths; default 0 |
FontFile | 1.0 | An embedded Type 1 program |
FontFile2 | 1.1 | An embedded TrueType program |
FontFile3 | 1.2 | An embedded program of the kind its Subtype names |
CharSet | 1.1 | For a Type 1 subset: the names of the glyphs in it, as a string such as (/A/B/C) |
A CIDFont’s descriptor can also have Style (a Panose classification),
FD (descriptors for parts of the font) and CIDSet (a stream
with a bit for each CID present in a subset).
Flags
Bit 1 is the lowest bit.
| Bit | Name | Meaning |
|---|---|---|
| 1 | FixedPitch | All glyphs are 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 only the standard Latin set and can use the standard encodings |
| 7 | Italic | The glyphs slant |
| 17 | AllCap | No lower-case letters |
| 18 | SmallCap | Lower-case letters are small capitals |
| 19 | ForceBold | Make thin stems bold at small sizes |
Exactly one of Symbolic and Nonsymbolic should be set. Flags 32 is
bit 6, a plain Latin font; Flags 4 is bit 3, symbolic.
Embedded font programs
An embedded font is a stream named by one of the descriptor’s three keys:
| Key | Since | Program | Extra stream keys |
|---|---|---|---|
FontFile | 1.0 | A Type 1 font in its PFA-like form: a clear-text part, a binary eexec-encrypted part and a part of 512 zeros and cleartomark | Length1, Length2, Length3: the lengths of the three parts |
FontFile2 | 1.1 | A TrueType font file, the same bytes as a .ttf, often a subset | Length1: the length of the font file after decoding |
FontFile3 | 1.2 | /Subtype /Type1C: a Type 1 font in Compact Font Format (CFF) | Subtype |
FontFile3 | 1.3 | /Subtype /CIDFontType0C: a CID-keyed CFF font, for CIDFontType0 | Subtype |
A CIDFontType2 font embeds its TrueType program with FontFile2, and a
CIDFontType0 font its CFF with FontFile3. Font streams may carry
Metadata from PDF 1.4.
Subsets
Writers often embed only the glyphs a document uses. A subset font’s name
starts with six upper-case letters and a plus sign, such as
EOODIA+Poetica, the same tag in BaseFont and
FontName. The tag is made up by the writer so that two different
subsets of one font in a file have different names.