Nyxiontech PDF Tools › PDF to text

Why text copied from a PDF pastes as gibberish

The page reads perfectly on screen. You select a paragraph, copy it, paste it into an e-mail, and out comes a run of boxes, accented capitals and punctuation that spells nothing. Your eyes and your clipboard are both working. The letters you can see and the characters the file hands out are simply two different things, and only one of them is broken. This guide shows how to tell which of four problems you have in a single click, why most of the advice you will find does not work, and the one setting that decides whether the real fix does anything at all.

Tell the four cases apart first

Open PDF to text, drop the file on it and click Extract text. What comes back names the problem:

Keep that last one separate from a different thing people call by the same name. A PDF can carry a flag saying that copying is not permitted. A flag is not encryption: the text sits in the file exactly as it does in any other PDF, and whether a program respects the flag is a decision that program makes. So if your paste is gibberish rather than blocked, copy protection is not the reason.

Why the page looks right and the copy does not

A PDF does not store letters. It stores a font and a list of codes, and for every code the font holds a drawing. Code 36 might draw an "a". Nothing in that arrangement has to record that code 36 means the letter a, because drawing the shape never required knowing what it was.

Copying does require knowing. For that, a font can carry a second table, the ToUnicode CMap, which the PDF specification describes as "A stream containing a CMap file that maps character codes to Unicode values" (ISO 32000-2, clause 9). When that table is missing, partial or wrong, the display is untouched, because the display never consulted it. Copying, searching and screen readers are the only things that break, which is exactly the pattern you are seeing.

It usually comes from subset fonts, where whatever produced the file renumbered the codes to suit itself and then wrote no correct table, or from a document that has been through a converter that rebuilt its fonts along the way. Older typesetting output, exports from accounting and banking systems and files that have been converted more than once are the common offenders.

Why the usual advice does not fix it

The fix: read the pixels, not the text layer

Optical character recognition looks at the page as a picture and works the letters out from their shapes, so the broken table never enters into it. One setting decides whether it happens at all.

  1. Open OCR: searchable PDF and add the file.
  2. Untick Skip pages that already contain text. It is ticked by default, and on this file it is the whole problem. The tool counts the characters on each page and skips any page carrying more than twenty of them. Your pages are full of characters. They are the wrong characters, but a count cannot tell, so every page is skipped and nothing happens. You will see it say so, naming the pages: "Skipped 12 page(s) that already had text".
  3. Set Language to match the document. The choices are Polish + English, which is the default, Polish, and English. Recognition leans heavily on what words look like in a given language, so the wrong setting costs real accuracy.
  4. Leave Quality on Accurate unless the print is small, where Small print is worth the wait. The settings render the page at 200, 300 and 400 dots per inch before reading it, so each step up is slower.
  5. Click Recognise text. It runs on your own processor, so a long document takes minutes rather than seconds, and the progress line names the page it is on.
  6. Click Copy recognised text. That is the text the recogniser produced, and it is the one you came for.

Do not copy out of the PDF it hands back. That file is your original with a new invisible text layer drawn over it, so the broken layer is still underneath, and anything extracting text from it gets both at once: the gibberish and the good text, interleaved. Copy recognised text gives you only what was recognised. This is the step almost every other guide leaves out, and it is why people report that OCR "did not work".

When you need a clean file, not just the text

If you have to pass on a PDF that other people can search and copy from, get rid of the broken layer before recognising anything:

  1. Open Compress PDF and pick any Level except Lossless. Those levels turn each page into an image, which is normally the cost and is here the point: the broken text layer goes with it. Lossless only repacks the file and would leave the layer exactly where it is.
  2. Run the result through OCR: searchable PDF. With no text left on the pages, the skip setting no longer changes anything, although there is no harm in leaving it unticked.

There is a price. The pages become pictures, so the text is only ever as sharp as the rendering, and the file may come out larger or smaller depending on what was in it. For a document you only need to read from, copying the recognised text is simpler and gives up nothing.

If what you want is a document you can edit rather than one you can search, PDF to Word builds a .docx instead, and how to convert PDF to Word without uploading it sets out what the conversion keeps and what it drops.

What recognition will not do

Open PDF to text to find out which case you have, then OCR: searchable PDF to fix it.