Learning Drawing a page

Text and fonts

1.4 ch. 51.7 §9

BT                      % begin text object; text matrix reset
/F1 12 Tf               % font resource F1 at 12 pt
14 TL                   % leading
72 720 Td               % move to start of line
(First line) Tj
T* (Second line) Tj     % T* = next line using leading
[(W) 80 (orld)] TJ      % TJ: strings plus kerning in 1/1000 em (positive moves left)
ET
The bytes in a string are character codes, not Unicode. The font's encoding maps code → glyph. Getting text back out (copy/paste, search, screen readers) needs a separate code → Unicode mapping, usually a /ToUnicode CMap. Without one, extraction is guesswork.

Font types

KindSubtypeWhat it is
Simple fonts
1-byte codes, up to 256 glyphs
Type1PostScript Type 1 (and CFF via FontFile3). Includes the standard 14 (Helvetica, Times, Courier families, Symbol, ZapfDingbats) that pre-2.0 readers must supply without embedding.
TrueTypeTrueType outlines, embedded as FontFile2
Type3Glyphs defined by content streams (/CharProcs), each starting with d0 or d1. Bitmap fonts, odd symbols.
MMType1Multiple Master instances (legacy)
Composite
multi-byte codes, CJK, large glyph sets
Type0A CMap (e.g. Identity-H) maps codes → CIDs, and one descendant CIDFont (CIDFontType0 = CFF, CIDFontType2 = TrueType) maps CIDs → glyphs. This is what modern generators use for any Unicode text.

A font descriptor holds metrics and flags plus the embedded program (/FontFile, /FontFile2, /FontFile3). In 1.6+, /FontFile3 can be /Subtype /OpenType. Subset fonts have names like /ABCDEF+Helvetica. The Font types and Standard 14 fonts references go into each in detail.

Read: 1.4 ch. 51.7 §9 Text extraction: 1.4 §5.91.7 §9.10

Text rendering modes (Tr)

0 fill; 1 stroke; 2 fill+stroke; 3 invisible; 4–7 the same plus add to clipping path. Mode 3 is how OCR'd scans put a searchable invisible text layer over the image.

Q1. Copy-paste from a PDF gives garbage characters. What is most likely missing?
A /ToUnicode CMap on the fontAn XMP metadata streamThe /MediaBoxA /StructTreeRoot
Check
Q2. Which font type do modern generators use for arbitrary Unicode text?
Type1TrueTypeType3Type0
Check
Q3. An OCR'd scan has searchable text over the page image. Which text rendering mode draws that text?
0, fill1, stroke3, invisible7, add to clipping path
Check
Reset3 questions

Section references such as 1.4 §3.4 1.7 §7.5 are to the Adobe PDF Reference, third edition (PDF 1.4) and ISO 32000-1:2008 (PDF 1.7). Where to get them: PDF specifications.