How to Extract Text From a PDF (and When You Need OCR)
By Docmint Team · · 4 min read
Drop the PDF into a text extractor, then copy the text or download it as TXT or Markdown. If nothing comes out, the PDF is a scan and needs OCR first.
To extract text from a PDF, open it in a text extraction tool such as Docmint's PDF to Text, review the text page by page, then copy it to your clipboard or download it as a TXT or Markdown file. This works instantly on PDFs that contain a real text layer. If the result comes back empty, the PDF is a scanned image, and you need to run OCR first to turn the picture of the words into actual characters.
How do you know if a PDF has real text?
A PDF can hold text in two very different ways. Documents exported from a word processor, a spreadsheet or a web page usually contain a text layer: each character is stored as a character, with a font and a position on the page. Documents made with a scanner or a phone camera usually contain only a picture of each page. On screen they look the same, but only the first kind has text a program can read.
The quickest test takes a few seconds. Open the PDF in any viewer and try to select a sentence with your cursor. If the words highlight one by one, there is a text layer. If you can only draw a box over the whole page, or searching finds nothing for a word you can clearly see, you are looking at an image.
Some files are a mix, such as a typed cover letter followed by scanned attachments. Extraction then picks up the typed pages and returns little or nothing for the scanned ones.
Why do scanned PDFs need OCR?
OCR (optical character recognition) looks at the shapes in an image and works out which letters they represent. Text extraction does not do this; it only reads characters that are already stored in the file. A scanned contract, a photographed receipt or an old fax saved as a PDF will produce an empty or nearly empty result, whichever extraction tool you use.
The fix is to run the file through OCR PDF first. It recognizes the text locally in your browser and can give you a plain text file directly, or a searchable PDF that you can then extract from like any other document. OCR is slower and never perfect, so if a digital original of the document exists, getting that is the better option.
How to extract text from a PDF with Docmint
PDF to Text runs entirely in your browser, so the file is never uploaded.
- Open PDF to Text and drop in a PDF that contains real text, not just a scan.
- Review the preview. The extracted text appears page by page, along with a count of characters, words and pages.
- Turn on "Keep layout" if you want to preserve line breaks and spacing, or leave it off to get flowing paragraphs.
- Copy everything to your clipboard with one click, or download the text as a .txt or .md file.
- To process several PDFs at once, drop them all in. Each one gets its own text file, bundled in a ZIP.
Should you keep the layout or get flowing paragraphs?
Without layout, the text comes out as flowing paragraphs. This is what you want when you plan to paste the content into an email, a document, a translation tool or an AI assistant, because lines are not broken wherever the PDF happened to wrap them.
With "Keep layout" on, line breaks and spacing are kept as they appear on the page. That suits anything where position carries meaning: invoices, forms, code listings, poetry and tables. Columns are separated with tabs, so a table copied this way pastes into a spreadsheet with each value in its own cell, often with little cleanup.
Multi-column layouts, such as academic papers and newsletters, are where extraction most often surprises people. Text in a PDF is stored in the order it was written to the file, which is not always the order you read it. If paragraphs from two columns come out interleaved, try the other layout setting and compare.
TXT or Markdown: which format should you download?
Plain text (.txt) opens anywhere: Notepad, TextEdit, any code editor, any form that accepts pasted text. It is the safest choice when you are moving the content into another program.
Markdown (.md) is still plain text, but it marks each page break as a heading, so you can tell where page 4 ends and page 5 begins. That helps with long reports you want to cite by page, with note-taking apps that read Markdown, and when you give a document to an AI tool in sections. Neither format keeps bold, italics or fonts.
Other ways to get text out of a PDF
For a single paragraph, selecting and copying in your PDF viewer is fine, and almost every viewer supports it, including the ones built into browsers and macOS Preview. With longer documents, copying from a viewer tends to bring stray line breaks and headers mixed into the body, and going page by page gets tedious. Some desktop PDF editors can export to text or Word, which is reasonable if you already own one. A dedicated extractor is faster when you want the whole document, a word count, or a batch of files handled at once.
Troubleshooting common problems
- Empty output: the PDF is a scan or a photo. Run it through OCR PDF, then extract.
- Symbols or gibberish instead of letters: some PDFs use fonts whose characters are not mapped to real text. The page looks fine, but the stored text is meaningless. OCR is the workaround here too.
- Hyphenated words split across lines: the original layout hyphenated them. A find and replace in your editor cleans this up.
- Headers, footers and page numbers mixed into the text: they are part of each page, so they are extracted too. Delete them afterwards, or remove pages you do not need with Delete Pages before extracting.