How to extract all the text from a PDF
Updated 2026-08-02 · 6 min read
Short answer: First test whether the PDF has a text layer: try to select a sentence. If text highlights, drop the file into a text extractor and export a .txt, you get every page at once with the reading order preserved. If nothing highlights, the pages are images and you must run OCR before any extraction will work.
Extracting text is the most reliable conversion out of PDF, because you are throwing the layout away rather than trying to rebuild it. Nothing has to be guessed except the reading order.
First: does the PDF have a text layer?
This one check determines everything that follows.
- Open the PDF Any viewer will do, including the one built into your browser.
- Try to select a sentence Click and drag across a line of text. If a blue highlight follows your cursor, there is a text layer.
- Or search for a word Press Ctrl+F and search for a word you can clearly see on the page. Found means text layer; not found means image.
- Watch for the mixed case Many documents have both: a typed cover page with real text and scanned pages inside. Test a page in the middle, not just the first one.
Extracting the text
With a text layer confirmed, drop the file into the text extractor. It reads the content streams, orders the runs, and gives you a plain .txt you can save, search, paste into a note or feed to a script. The whole thing runs in your browser, so a confidential document is never uploaded.
Alternatives that work just as well for a one-off: select all in your PDF viewer with Ctrl+A and paste into a text editor; or upload to Google Drive and open with Google Docs, which also OCRs scanned pages automatically for roughly the first ten pages.
Extract the full text as a .txt file, entirely in your browser.
What you will need to clean up
| Artefact | What you see | Fix |
|---|---|---|
| Hyphenation at line ends | inter-\nnational | Find and replace "-\n" with nothing |
| Line breaks inside paragraphs | A break every 70 characters | Replace double breaks with a marker, single breaks with a space, then restore |
| Ligatures | fi fl ff as single characters | Replace fi with fi, fl with fl, ff with ff |
| Smart quotes and dashes | “ ” ‘ ’, | Replace with straight equivalents if a script needs them |
| Repeating headers and footers | The document title on every page | Remove with a find-and-replace or a regex |
| Column interleaving | Two columns merged line by line | Extract with a layout-preserving mode, or crop the columns separately |
| Missing spaces | Wordsrunningtogether | The PDF positioned glyphs without space characters; needs manual repair |
| Mojibake | □ or é instead of é | The font has a broken encoding map, OCR the page instead |
Common artefacts in extracted PDF text and how to fix them.
Note: Reading order is the one thing extraction still has to guess. A PDF stores drawing operations in whatever order the generator emitted them, which for a two-column page is often column one then column two, but is sometimes interleaved. If your output reads like two conversations mixed together, extract each column separately by cropping the page, or use a layout-aware extractor.
For developers
Poppler ships pdftotext, which is the reference implementation and available on every platform. The -layout flag preserves the visual column arrangement using spaces, which is exactly what you want before importing into a spreadsheet.
# Preserve column layout, best for tables
pdftotext -layout report.pdf report.txt
# Just pages 10 to 20, reading order only
pdftotext -f 10 -l 20 report.pdf excerpt.txt
# UTF-8 output with no page break characters
pdftotext -enc UTF-8 -nopgbrk report.pdf clean.txt
In JavaScript, pdf.js exposes page.getTextContent(), which returns each text item with its transform matrix so you can implement your own reading-order logic. In Python, pdfplumber and PyMuPDF both give you words with bounding boxes.
When there is no text layer
A scan needs OCR before extraction is possible at all. Three things drive accuracy more than the choice of engine:
- Resolution. 300 DPI is the sweet spot. Below 200 DPI accuracy falls sharply; above 400 DPI you gain almost nothing and slow everything down.
- Straightness. A page scanned at three degrees off square measurably hurts recognition. Deskew first.
- Contrast. Clean black on white beats a grey photocopy every time. Greyscale scans of text OCR better than colour ones.
On a clean 300 DPI scan of printed text, expect 98-99.5 percent character accuracy. On a fax, a grey photocopy or a phone photo taken at an angle, expect considerably less. Handwriting is a different problem and general OCR engines do badly at it. See how to OCR a scanned PDF for the full method.
Text, Word or Excel?
| You want | Use |
|---|---|
| The words, to search, quote or feed to a script | Text extraction |
| An editable document to rewrite | PDF to Word |
| Numbers in columns | PDF to Excel |
| The pictures rather than the words | Extract images |
| The original PDF to become searchable | OCR in place, not extraction |
Frequently asked questions
How do I copy all the text from a PDF at once?
Open the PDF, press Ctrl+A to select everything, then Ctrl+C and paste into a text editor. For multi-page documents, a text extractor is more reliable because it walks every page in order and exports a single .txt file.
Why can I not select text in my PDF?
The page is an image, not text. This happens with anything from a scanner, a fax or a phone camera, and occasionally with PDFs exported deliberately as images. Run OCR to add a text layer, then selection and search start working.
Why does my extracted text have random line breaks?
PDF stores each visual line separately with no notion of a paragraph, so extractors emit a break per line. Replace double breaks with a placeholder, replace single breaks with a space, then restore the placeholder to get paragraphs back.
Does extracting text from a PDF change the original file?
No. Extraction reads the file and writes a new .txt. Your PDF is untouched. OCR is different, it adds an invisible text layer to the PDF, which is a modification, so keep a copy of the original.
Can I extract text from a password-protected PDF?
If you can open it with the password, yes, extraction works normally once the document is decrypted in the viewer. If the file has an owner password restricting copying, you must remove that restriction legitimately first, which requires the password.