Extracting Text From PDFs: Text Layers and OCR
Some PDFs hand over their text in a second; others contain only pictures of pages and need OCR. This guide explains how text is stored in a PDF, why extracted text can come out garbled or in the wrong order, how OCR reads scanned pages and what affects its accuracy, and how to check the result before you rely on it.
Two Kinds of PDF Pages
A PDF page can carry text in two ways. Most PDFs exported from a word processor, browser or design program have a text layer: each character is stored as a code in a font and placed at a position on the page. A scanned or photographed page is different. It is one picture of the page, and to software the letters on it are only pixels.
| Kind of page | How it was made | What extraction returns |
|---|---|---|
| Text PDF | Exported or printed to PDF from an app | The stored characters, usually exactly |
| Scanned PDF | Scanner, phone camera or fax | Nothing until OCR reads the image |
| Searchable scan | A scan with an OCR text layer added later | That earlier OCR result, with its errors |
| Outlined text | Text turned into shapes in a design program | No characters; only OCR can read it |
A PDF viewer usually tells you which kind you have. If you can select a single word or find it with the search box, the page has a text layer. If dragging selects the whole page as one block, or the search finds nothing, the page is an image. One file can mix both, such as a typed report with scanned appendices.
How Text-Layer Extraction Works
A PDF does not store paragraphs. It stores runs of characters, each with a font and a position, often a word or a few letters at a time, in whatever order the program that wrote the file chose. An extractor reads these runs and rebuilds lines from their positions.
The LeedyBox PDF to Text tool reads the runs with PDF.js, the PDF engine used in Firefox. It starts a new line when the vertical position changes by more than 5 points (about 1.8 mm) and otherwise joins runs with a space, and each page in the result begins with a marker such as --- Page 1 ---. Most single-column documents come out readable, with a few side effects:
- A word stored as several runs, for example because of letter spacing, can come out with spaces inside it.
- Columns, sidebars and captions appear in the order they are stored, which can differ from the order in which you read them.
- Superscripts, footnote marks and other text set higher or lower than the line can start a line of their own.
- Running headers, footers and page numbers are part of each page's text.
Why Extracted Text Can Look Garbled
Inside a PDF, text is stored as glyph codes of a font, not as Unicode characters. To turn the codes back into letters, the file needs a mapping. Well-made PDFs include a ToUnicode table for each font, and fonts with a standard encoding can be decoded without one. Trouble starts when a font is embedded as a subset with its own numbering and no mapping: the codes mean nothing outside the file, so extraction produces wrong letters, symbols or empty boxes even though the page looks fine.
Chinese, Japanese and Korean fonts often rely on predefined character maps (CMaps) such as Adobe-Japan1 or Adobe-Korea1 instead of their own tables. The LeedyBox tool loads these CMaps together with PDF.js, which fixes many East Asian documents that simpler extractors get wrong. Other common causes are ligatures such as fi stored as one glyph, Type 3 fonts whose letters are drawn as shapes and often lack a mapping, and PDFs whose encoding was scrambled on purpose to make copying harder.
When a page has a text layer, the tool uses it, even if that text is garbled, and does not run OCR on the page. To read such a page with OCR instead, convert it to an image with PDF to JPG and read the image with Image to Text (OCR).
When the LeedyBox Tool Uses OCR
The tool decides page by page. If the text layer of a page has fewer than 15 characters, the page is drawn as an image at twice its normal size, about 144 pixels per inch, and read with Tesseract.js in the language chosen under "OCR Language" together with English. In a document with typed pages and scanned pages, the typed pages are therefore read exactly and only the scans go through OCR.
A scanned page with a few characters from a stamp or a page number still counts as empty and goes to OCR. A scan that already has a text layer of 15 characters or more does not, so a poor OCR layer added by a scanner is passed through as it is. The OCR engine and its language data are downloaded from leedybox.com the first time OCR runs, which makes the first scanned page slower. Your PDF is read in the browser and is not uploaded.
How OCR Turns Pixels Into Text
OCR works in stages. The engine first turns the image into black and white and finds blocks of text, lines and words, a step called page segmentation. Each line is then read by a neural network trained on one language or script, which picks the most likely sequence of characters, helped by the language's word lists. The result is a best guess rather than a copy: similar shapes such as 0 and O, 1, l and I, or rn and m can be confused, and words missing from the language data are misread more often.
The language setting matters more than any other option. A model trained on Latin letters cannot read Thai or Japanese, and text in a language that is not selected usually comes out as wrong characters. Every option in the LeedyBox tool except "English only" combines the chosen language with English, which helps with mixed documents such as a Korean contract with English product names.
What Affects OCR Accuracy
| Factor | Effect | What helps |
|---|---|---|
| Resolution | Small print loses the detail that tells letters apart | Scan at 300 DPI or more; more for small print |
| Skew and curvature | Tilted lines and curved book pages confuse line detection | Scan flat and straight; photograph from directly above |
| Contrast and noise | Grey backgrounds, stains, show-through and JPEG artefacts look like marks | Clean scans with dark text on a white background |
| Fonts | Decorative, very thin or very bold fonts are misread more often | Check the result carefully |
| Handwriting | Tesseract is trained on printed text | Expect poor results; type the text instead |
| Vertical text | Vertical Japanese or Chinese is often misread | Check carefully, or retype |
Because the tool renders pages at about 144 pixels per inch, small print such as footnotes or the fine print of a contract can be hard to read even from a good scan. For such pages, PDF to JPG renders pages at a higher resolution, and Image to Text (OCR) can read small text again at twice the size and raise the contrast before recognition.
Tables, Columns and Layout
The result is plain text. Tables lose their grid, multi-column pages can come out column by column or line by line across the columns, and text boxes and captions land wherever the file or the OCR engine placed them in the reading order. Recognising words and rebuilding a layout are separate problems, and the tool solves only the first. For tables of figures, check every value against the original or retype the table in a spreadsheet; for long documents, rebuild headings and paragraphs in your editor after extracting the text.
Checking and Cleaning the Result
- Compare a few numbers, names and dates with the original; OCR errors in figures are easy to miss.
- Search for typical confusions: 0 and O, 1, l and I, 5 and S, rn and m, and missing accents or tone marks.
- Rejoin words hyphenated at the end of a line and lines broken inside paragraphs.
- Remove the page markers, running headers and page numbers if you need continuous text.
- Keep the result with "Copy Text" or "Save as .TXT"; the saved file is plain UTF-8 text.
Frequently Asked Questions
Why does a page come out empty?
The page had no text layer and OCR found nothing it could read: the scan may be blank, very faint or too small, or the text may be handwritten. Try a clearer scan, or convert the page with PDF to JPG and use Image to Text with its contrast and enlargement options.
Can it read password-protected PDFs?
Not a PDF that asks for a password when it opens; the tool shows an error instead. Open the file in a PDF viewer with the password and save an unprotected copy first, if you are entitled to.
Can the tool make a searchable PDF?
No. The result is plain text that you can copy or save as a .txt file, and the PDF itself is not changed. Programs that make searchable PDFs add an invisible OCR text layer on top of each scanned page.
Why is OCR slow on long documents?
Each scanned page is drawn as an image and recognised in your browser, one page after another, after the OCR engine and language data have been downloaded. A page can take several seconds or longer on a slower device. Pages with a text layer are much faster because they need no recognition.