A PDF page stores its text as codes that pick shapes from a font, which is enough to draw it. To copy, search or read the text aloud, a viewer must also know which character each code means. A ToUnicode map answers that for one font, code by code: this code is “R”, that one is “é”, and so on.

When does a PDF need a ToUnicode map?

When nothing else says what the codes mean. A simple font with a standard encoding, such as Mac Roman or WinAnsi, already names its letters. A font whose codes are just positions in the font, as with the Identity encoding of CID fonts or a custom encoding, needs a map for reliable copying. When every method fails, in the standard’s words: “If these methods fail to produce a Unicode value, there is no way to determine what the character code represents”.

Where do you see it?

pdffonts (from Poppler, brew install poppler) says yes in its uni column when a font has a map, with a caution in its manual: “the absence of a ToUnicode map doesn’t necessarily mean that the text can’t be converted to Unicode”. The demo cover letter made for PDF Textfix’s screenshots shows the common case of a file that needs none:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
AAAAAB+IBMPlexSerif-SemiBold         TrueType          MacRoman         yes yes no       8  0
AAAAAC+IBMPlexSerif-Regular          TrueType          MacRoman         yes yes no       9  0

Both fonts use Mac Roman, a standard encoding that already names every letter they draw, so neither carries a map, and pdftotext extracts the heading as “Renee Okafor” all the same. A font that does carry one keeps it in a small stream of its own, which qpdf --show-object=N --filtered-stream-data prints. Its heart is a list of lines such as:

<52> <0052>

Code 52 (hexadecimal) is U+0052, “R”. A font whose codes are its own needs one such line for every character it draws.

What happens when the map is missing or wrong?

The page looks right, but copying gives other letters or symbols, search finds nothing and a screen reader reads nonsense. Drawing does not use the map, so the page itself does not change; only the text a viewer copies does. We gave the SemiBold font of a copy of the demo cover letter a deliberately wrong map, one line that calls code 52 “B”. The page drew exactly as before; pdftotext did not:

Renee Okafor    the cover letter as made
Benee Okafor    the copy with the wrong map

The signature at the foot of the letter still came out as “Renee Okafor”: it is set in the Regular font, and a map belongs to one font only. A font with codes of its own and no map can go wrong the same way for every character. The guide to gibberish when copying from a PDF covers the causes and fixes.

What does it mean for an edit?

An editor has to know which character every code stands for: to show you the line as text, and to write your new characters with the right codes. In PDF Textfix, simple TrueType fonts are editable with or without a map. When PDF Textfix cannot identify any character of a line, it locks the line and says why: “No character of this line is known, so it cannot be edited.” The manual’s list of locked lines gives every such reason. It never modifies a font that is already in the file, its map included.

Questions about ToUnicode maps

How do I fix a PDF with a missing or wrong ToUnicode map?

Export it again from the source document. When that is impossible, OCR recognizes the text from the page image, at the cost of accuracy.

Does a ToUnicode map change how the page looks?

No. Drawing uses the font’s shapes; the map only explains them.

What is a CMap?

A table of codes. A CID font’s CMap maps the text’s codes to the font’s character numbers; a ToUnicode CMap maps codes to Unicode text.