Why Does Text Come Out Garbled When Copied From a PDF?

Copy text out of a PDF and one of three things happens: it pastes cleanly, the words run together, or you get complete gibberish. Each has a different cause.

Updated:

How PDF stores text

A PDF does not store words or sentences. It stores positioned glyph drawings: "draw glyph 65 of this font at these coordinates". You read "hello" on the page, but the file holds five separate drawing instructions.

Copying reads those instructions back and tries to turn them into text. That is a translation, and it does not always work.

Three different failures

SymptomCauseFixable?
Nothing copies at allScanned document, no text layerYes, with OCR
Nonsense charactersMissing font mapping (ToUnicode)Hard; OCR is more practical
Words run togetherPosition jumps instead of space charactersPartly, by hand
Line breaks disappearNo paragraph structureBy hand
Columns interleaveReading order undefinedBy hand

Where the gibberish comes from

Every font has its own glyph numbering, and those numbers need not match Unicode code points. The PDF producer is supposed to embed a ToUnicode table saying which glyph corresponds to which character.

When that table is missing or broken, the copying program treats glyph numbers as character codes and you get garbage. The page still looks right, because the drawing instructions are intact; what is broken is only the record of "which letter this shape was".

Advertisement

Why words run together

A space in a PDF is not always a space character. Producers often say "draw the next word 4 units to the right" with no character in between. The copying program has to infer the space.

When the inference threshold is off, two things happen: narrow gaps are ignored and words merge, or normal letter spacing is read as spaces and a single word comes out as "w o r d". The second is common in headings and letter-spaced designs.

Reading order in multi-column documents

On a two-column page, in what order is the text stored? PDF does not define that — drawing order need not match visual reading order. So text copied from a two-column academic paper can alternate a line of the left column with a line of the right.

Some documents carry a "tagged PDF" structure that resolves this (documents produced for accessibility usually do). Most do not, and then selecting one column at a time is the only practical approach.

What to do

  1. Test first: Copy one paragraph into a plain text editor. Do not look for a fix before you have seen the failure.
  2. Nothing copies: The document is scanned; you need OCR.
  3. Gibberish: The font mapping is broken; rasterise and OCR.
  4. Text present but messy: Copy in small sections and clean up with find-and-replace.
  5. Multi-column: Select each column separately.

One last warning: do not take copied text on trust, especially numbers. Confusions between 1/l, 0/O and 5/S occur both in OCR and in broken mappings, and they are the hardest kind of error to spot.

Frequently asked questions

Why is the copied text nonsense?

The ToUnicode table that maps the font's glyph numbers to Unicode characters is missing or broken. The page still looks right because the drawing instructions are intact; only the record of which letter each shape was is damaged.

Why do words run together?

A space in a PDF is not always a space character; producers often just draw the next word slightly to the right. The copying program has to infer the gap, and a wrong threshold merges words.

Why do lines interleave in two-column documents?

PDF does not define reading order, and drawing order need not match visual order. In documents without tagging, selecting one column at a time is the only practical approach.

Can a broken font mapping be repaired?

Not in practice. The text is not present in readable form in the file. The fix is to rasterise the pages and regenerate the text with OCR.

More guides

Try Konta PDF

Merging, splitting, reordering, encrypting, OCR and image-to-PDF are free. Files are processed in your browser.

Open the tools