Guides

Why PDF Text Comes Out Garbled (and How to Fix It)

Why PDF Text Comes Out Garbled (and How to Fix It)

PDF text comes out garbled when the character codes stored in the document’s content stream do not map back to standard Unicode characters. This usually occurs because the PDF uses subset fonts without a ToUnicode CMap table, relies on non-standard font encodings, or consists of scanned page images with no underlying text layer at all. While the PDF viewer correctly draws visual glyph shapes on screen, copying or extracting the text yields symbols, random letters, boxes, or empty output.

This comprehensive guide explains the structural reasons why PDF text turns into gibberish, provides a detailed diagnostic matrix to identify your exact issue, and walks through practical methods to extract text from a PDF cleanly — entirely within your web browser without uploading sensitive files to external servers.

Key definitions: ToUnicode CMap, glyph codes, and subset fonts

To diagnose why text extraction fails, it is essential to understand the technical terms that define PDF font architecture under ISO 32000 (the PDF specification):

Glyph code (Character index) — an internal numeric index used by a font program to locate and draw a specific vector shape (glyph) on screen or paper. Glyph codes do not inherently correspond to human-readable letters or ASCII values; they are simply entry positions within a font’s internal character map.

ToUnicode CMap (Character Map) — an optional stream embedded within a PDF font object that explicitly maps internal glyph codes to standard UTF-16 Unicode character sequences. When you copy text from a PDF or process it with an extraction tool, the software relies on the ToUnicode CMap to translate glyph indices back into actual letters.

Font encoding — an array or dictionary that maps 1-byte or 2-byte character codes in a content stream to specific glyph names within a font. Standard encodings include WinAnsiEncoding, MacRomanEncoding, and StandardEncoding. Non-standard or custom encodings define arbitrary character mappings.

Subset font — a custom, trimmed version of a font embedded inside a PDF containing only the character glyphs actually used in that specific document. To optimize file size, PDF creation software frequently renumbers the glyph indices in a subset font starting from 1 or 0, severing the original relationship between glyph index and standard ASCII/Unicode values.

How PDFs render text vs. store text: drawing instructions vs. character codes

The primary reason text extraction produces unexpected results lies in the fundamental design of the PDF file format. Unlike word processors or HTML documents, which store structural text streams that are subsequently styled, a PDF is primarily a graphical page description language based on PostScript.

A PDF content stream contains explicit visual positioning instructions, such as: “Select Font /F1 at 12pt, move coordinate to (72, 750), and draw glyph indices [34, 12, 88, 12, 45]”. The PDF viewer reads the embedded font file, looks up glyphs 34, 12, 88, and 45, and renders the visual vector outlines for the word “Hello” onto the canvas.

However, when a user highlights that word to copy it, or when an automated tool extracts the text, the software does not analyze the visual shapes drawn on screen. Instead, it reads the numerical array [34, 12, 88, 12, 45] and queries the font’s ToUnicode table for translation:

  • If ToUnicode maps 34 → U+0048 (H), 12 → U+0065 (e), 88 → U+006C (l), and 45 → U+006F (o), extraction succeeds perfectly.
  • If ToUnicode is absent or corrupted, the extraction tool attempts to guess using fallback encodings, resulting in output like "$%#%&" or character-shifted gibberish.

Cause 1: Subset fonts with no ToUnicode table

Font subsetting is the single most common cause of garbled text in modern digital PDFs. When a document creator exports a PDF from desktop publishing software (such as Adobe InDesign, Microsoft Word, or LaTeX), the software embeds a font subset to save bandwidth and memory. For example, a font named Helvetica is embedded as a subset named XJFAAA+Helvetica containing only 20 character glyphs.

During subset creation, the generator frequently renames and reorders the internal glyph IDs. Glyph A might become ID 1, glyph e becomes ID 2, and glyph t becomes ID 3. If the PDF generator writes a valid ToUnicode table into the document header, text search and copy function normally. However, many legacy, low-cost, or virtual printer drivers fail to generate this ToUnicode CMap stream.

When you attempt to extract text from such a PDF, the extraction engine reads internal glyph IDs (1, 2, 3) without a translation dictionary. The engine falls back to standard ASCII or Latin-1 mapping, returning character-shifted text where every letter is offset by a fixed number of positions (e.g., “bcd” instead of “abc”, or random punctuation symbols).

Cause 2: Non-standard or legacy encodings and ligature collapse

Documents created using legacy PostScript Type 1 fonts, custom TrueType encodings, or specialized typesetting systems often suffer from encoding mismatches rather than complete mapping absence.

Custom encoding matrices: Older PDF generators frequently used custom 8-bit encoding vectors to display non-English characters, mathematical symbols, or custom dingbats. If the PDF specifies a custom encoding without providing a corresponding Unicode translation, characters extract as incorrect symbols (e.g., accented vowels like “é” extract as “é” or square boxes).

Typographic ligatures: Professional typography replaces common adjacent character pairs—such as “fi”, “fl”, “ffi”, or “ft”—with single combined glyph shapes known as ligatures. In poorly constructed PDFs, the ligature glyph (e.g., “fi”) is assigned a single private-use Unicode code point or lacks decomposition rules. When extracted, words like “file” or “offline” become “le” or “oine”, causing missing letter gaps in the extracted text.

Cause 3: Scanned page images with no text layer

A frequent misconception occurs when users attempt to copy text from a document created by a physical scanner, desktop copier, or mobile scanning app. A scanned PDF does not contain text streams, fonts, or character codes; it is simply a raster photograph (JPEG, PNG, or CCITT compression) wrapped inside a PDF page object.

Because human eyes instantly recognize the letter shapes in the image, users expect to select text. However, PDF viewers cannot highlight individual characters unless an Optical Character Recognition (OCR) process has previously scanned the image and generated an underlying invisible text layer. Attempting to extract text from a pure scanned PDF without OCR returns completely empty output or throws empty-stream warnings. To verify if your file is scanned vs. searchable, consult our detailed guide on scanned vs. searchable PDFs.

Cause 4: Copy protection and DRM permission flags

The PDF specification supports security handlers and encryption dictionaries that enforce user access permissions (Standard Password Security with 128-bit RC4 or 256-bit AES encryption). Document authors can explicitly disallow text extraction while allowing document viewing and printing.

When document security settings restrict copying, PDF readers render the text visually on screen but intentionally refuse to copy characters to the system clipboard. When programmatic extraction tools attempt to parse encrypted or protected streams without the owner password, the extracted output yields empty strings, null bytes, or scrambled ciphertext.

Cause 5: Right-to-Left (RTL) and CJK text encoding complexities

Documents written in Right-to-Left languages (Arabic, Hebrew, Persian) or Complex Character Scripts / CJK (Chinese, Japanese, Korean) introduce additional encoding and layout challenges:

  • Bidirectional (BiDi) reordering: PDFs store text in visual reading order (left-to-right positional coordinates on the canvas) rather than logical reading order. Without explicit BiDi structuring metadata, extracted Arabic or Hebrew text extracts backward (reversed character sequence) or with disconnected letter forms.
  • Multi-byte CID fonts: CJK character sets require 16-bit CIDFont dictionaries (Character Identifier fonts). If the CID-to-Unicode mapping stream is incomplete, CJK characters extract as unprintable hexadecimal codes or wide multi-byte garbage symbols.

Diagnostic matrix: identifying your exact PDF text issue

Use this diagnostic table to determine why your PDF text extracts as garbage and find the appropriate resolution:

Symptom in Extracted Text Primary Cause Underlying Technical Issue Recommended Fix
Letters shifted by fixed offset (e.g., “gftu” for “test”) Subset Font Missing ToUnicode CMap table in font object Run Image to Text (OCR) on rendered pages
Accented letters extract as “é”, “?”, or black boxes Legacy Encoding Non-standard 8-bit encoding vector without UTF-8 mapping Use PDF Text Extractor with Unicode normalization
Words miss letter pairs (e.g., “le” instead of “file”) Ligature Mismapping “fi”/”fl” ligatures lack decomposition mapping Apply automated regex post-processing for ligatures
Extracted text is 100% empty or blank Scanned Document Raster image object with zero embedded character streams Run OCR via Image to Text
Arabic/Hebrew text extracts completely backward BiDi Layout Order Visual coordinate ordering without logical BiDi metadata Apply BiDi string reversal post-processing
Selection disabled / Clipboard pastes empty strings DRM Security Encrypted PDF dictionary restricting copy permissions Unlock document with owner password prior to parsing

How to fix garbled PDF text: step-by-step solutions

Depending on the root cause identified in the diagnostic matrix, apply the following technical recovery steps:

Step 1: Repair Compressed Object Streams & Broken Cross-Reference Tables
If a PDF opens blank in older viewers, fails to load in automated parsers, or uses PDF 1.5+ compressed object streams (/Type /ObjStm and compressed xref streams), run it through our browser-based PDF Repair Tool first. It decompresses non-standard object streams and writes a clean, standard cross-reference table locally in your browser.

Step 2: Test with a browser-native text extractor
Before assuming a PDF’s fonts are irreparable, test the file using EasyExtract’s PDF Text Extractor. Modern browser engines utilize advanced PDF parsing libraries (PDF.js) capable of resolving complex font encodings, expanding standard ligatures, and reconstructing character streams that basic copy-paste operations corrupt.

Step 3: Fall back to Optical Character Recognition (OCR)
When a PDF contains subset fonts without ToUnicode maps or legacy custom encodings, programmatic character extraction from the content stream is mathematically impossible because the translation key does not exist. The only reliable solution is to render the PDF page to a high-resolution raster image (300 DPI) and run Optical Character Recognition (OCR). The OCR engine analyzes the visual shapes of the rendered glyphs rather than reading the broken character codes. For single-page documents or extracted image pages, use our browser-based Image to Text (OCR) tool.

Step 3: Print to PDF (Regenerate Font Stream)
For digitally created PDFs with minor encoding quirks, opening the document in a PDF viewer and selecting Print → Save as PDF can sometimes force the operating system’s print subsystem to re-encode the fonts and generate a fresh, compliant ToUnicode table.

When OCR is the only reliable solution

It is important to understand when programmatic text extraction reaches its absolute limit. In the following three scenarios, attempting to fix or repair the embedded text stream will fail, and OCR is mandatory:

  1. Pure Scanned Documents: The PDF contains only image streams (XObject subtype /Image). There are zero text operators (Tj, TJ) in the page content stream.
  2. Unmapped Subset Fonts: The font is subsetted, glyph indices are reordered, and no ToUnicode stream exists in the PDF binary data.
  3. Rasterized Text Objects: Text that was rendered as vector paths (outlined curves) or converted to flattened image layers during graphic design export.

In all three cases, OCR bypasses the underlying missing or broken text data by converting the visual canvas back into fresh, clean Unicode text.

Privacy and safety: in-browser PDF processing

Fixing garbled text often involves processing confidential financial statements, legal contracts, or medical records. Using third-party cloud OCR or PDF repair websites poses severe security risks, as your private files are uploaded to remote servers where they may be stored, logged, or exposed.

EasyExtract operates 100% in your browser. Both our PDF Text Extractor and Image to Text (OCR) tools execute client-side JavaScript WebAssembly code directly on your local device. Your PDF bytes never touch an external server, preserving complete data confidentiality and regulatory compliance (GDPR, HIPAA).

Frequently asked questions

Why does copied PDF text turn into gibberish?
PDF text turns into gibberish when the file’s embedded font lacks a ToUnicode CMap table or uses a custom encoding. The PDF viewer knows how to draw the visual glyph shapes on screen, but it has no map to translate internal character codes into standard Unicode letters when copied.

Why is my extracted text shifted by one or two letters (e.g., “gftu” instead of “test”)?
This character-shifting phenomenon occurs in subsetted fonts where character indices were renumbered sequentially during PDF creation. Without a ToUnicode table, the extractor reads character index 1 as ‘a’, index 2 as ‘b’, causing a fixed offset across all extracted text. OCR resolves this issue.

Why can’t I select or highlight any text in my PDF?
If you cannot highlight text with your cursor, the PDF is almost certainly a scanned document containing page photographs rather than embedded text streams. You must process the document with OCR to generate selectable text.

Why do extracted words have missing letters like “fi” or “fl”?
Missing letter pairs occur when the PDF uses typographic ligatures (combined glyphs for character pairs like “fi” or “fl”) without declaring Unicode decomposition rules in the font dictionary. Advanced extraction tools like EasyExtract automatically reconstruct standard ligatures.

How do I convert a scanned or garbled PDF into clean text?
First, test the file in EasyExtract’s PDF Text Extractor. If the output remains scrambled or empty, render the document pages and process them using an OCR tool like Image to Text.

Can I repair a garbled PDF text layer without re-typing it?
Yes. Running an OCR engine over the PDF generates a fresh, clean text layer overlaid onto the original document, restoring full searchability and copy capability without manual re-typing.

Does EasyExtract upload my PDF files to a server?
No. All EasyExtract tools parse files 100% client-side inside your web browser. Your document content remains strictly private on your device.

Sources:

Last updated: 17 September 2026.

Shah Abrar Ahmad - Founder & Lead Engineer
Lead Architect & Founder

Software architect and technical web engineer specializing in browser-based zero-knowledge file parsing, technical SEO, and data extraction security. Built EasyExtract to give users 100% private in-browser tools with zero cloud uploads.

Keep reading