Why you can't copy text from some PDFs, or get gibberish
Updated · Tested with pypdf 7.2.0, pdfminer.six 20260107, PyMuPDF 2.2, Poppler 25.03, OCRmyPDF 17.14
In short
Either the page is a picture with no text in it, or the file leaves out the table that says which letter each shape stands for, so copying gives symbols. A scan needs OCR. A file with a missing table can often be read by a tool that looks inside the font, and otherwise needs OCR too. A third cause is the author switching copying off.
A PDF is a description of how a page looks, not of what it says. Whether you can copy its text depends on how the file was made. There are four causes, and each has a different fix.
| What happens | Cause | Fix |
|---|---|---|
| Nothing can be selected | The page is a picture: a scan or a photo | OCR |
| Text selects but pastes as symbols | The font has no table saying which letter each shape is | Read the font itself, or OCR |
| Copying is greyed out | The author switched copying off | The password, or the author |
| Text pastes, but words are missing letters or run together | Joined letters and missing spaces | A better extractor |
1. The page is a picture
A scanner or a phone camera produces an image. Saved as a PDF, it is still an image: there are no letters in the file, only dots. You can check in any viewer: if you cannot select a single word, it is a scan.
The fix is OCR, which reads the picture and writes the text back in. Scanned or searchable? shows how to check a file in code and how to make it searchable.
2. The text pastes as gibberish
This is the confusing one. The page looks perfect, you can select the words, and what you paste is this:
&203$1<(;75$&7
&RPSDQ\QDPH +DUERU/DQH/RJLVWLFV/WGA PDF does not store letters. It stores numbered shapes from a font, plus a table, called ToUnicode, that says which letter each number stands for. When the program that made the PDF leaves that table out, the viewer can still draw the page, but nobody is told that shape 38 is a "C".
no-unicode-map.pdf is the sample extract with those tables removed. You can see that they are missing:
from pypdf import PdfReader
reader = PdfReader("no-unicode-map.pdf")
for name, ref in reader.pages[0]["/Resources"]["/Font"].items():
font = ref.get_object()
print(font["/BaseFont"], "has a map" if "/ToUnicode" in font else "no ToUnicode map")/HUHQIP+Noto-Sans no ToUnicode map
/SDIUIR+Noto-Sans-Bold no ToUnicode mapFix one: a tool that reads the font. The font file inside the PDF usually still knows which letter each shape is. Some tools look there when the table is missing, and some do not. On this file:
| Tool | Result |
|---|---|
| pypdf | Gibberish |
| PyMuPDF | Gibberish |
| pdftotext | Gibberish |
| pdfminer.six, pdfplumber | Correct text |
| 100sands | Correct text |
from pdfminer.high_level import extract_text
print(extract_text("no-unicode-map.pdf")[:29])COMPANY EXTRACT
Company nameFix two: OCR the page anyway. When the font is no help either, treat the page as a picture. OCRmyPDF renders each page, reads it, and writes a new PDF with a correct text layer:
ocrmypdf --force-ocr no-unicode-map.pdf fixed.pdfAfter that, pypdf reads fixed.pdf as COMPANY EXTRACT, Company name Harbor Lane Logistics Ltd, and so on. --force-ocr is needed because the file already has text, even though it is the wrong text.
3. Copying is switched off
A PDF can carry permissions: printing allowed, copying not. Viewers respect them and grey out Copy. This is a setting, not encryption of the content, and it is the author's decision; ask for an unrestricted copy. A file that needs a password just to open is a different case, covered in password-protected PDFs.
4. Letters go missing or words run together
Two smaller effects produce text that is almost right.
Joined letters. Many fonts draw "fi", "fl" or "ffi" as a single shape, called a ligature. A careless extractor returns that shape as one odd character or drops it, so "office" becomes "oce" or "ofce". Every library we tested handles this correctly today; if you see it, update your tools.
Missing spaces. A PDF often has no space characters at all: words are simply placed apart. The extractor has to guess where a gap is wide enough to be a space. Too strict, and Companyname runs together; too loose, and Comp any splits. If a tool gets this wrong for your files, switch to one that lets you tune it. pdfplumber's extract_text(x_tolerance=...) is the usual choice.
How to tell which case you have
- Try to select one word in a viewer. Nothing selects: it is a scan.
- Paste the selection into a text editor. Symbols instead of letters: the font has no map.
- Copy is greyed out in the menu: permissions.
- The paste is nearly right: ligatures or spacing.
For files you receive in bulk, do the same check in code, and send only the pages that need it to OCR, which is slow compared with reading text that is already there.