← Back to Blog

Extract Text from a PDF: 4 Methods That Actually Work

October 28, 2026

Extracting text from a PDF means pulling the text out of the file as editable text, for example to paste it into a document, search it, or process it further. This works directly when the PDF contains a text layer, meaning the text was embedded when the file was created. Scanned PDFs have no text layer: the page is just an image, and the text first has to be read by optical character recognition (OCR). So the first question is always what kind of PDF you are dealing with.

Extract text from a PDF by copy and paste

The fastest method needs no extra software. Open the PDF in a PDF reader, select the text you want or everything with Ctrl+A or Cmd+A, copy it, and paste it into a text document or word processor. For short passages from a cleanly created PDF, that is entirely sufficient.

Two limitations are worth knowing. First, the reader outputs the text in the order it is stored in the file, which is not necessarily the order you read it on the page. With multi-column layouts, text boxes, or footnotes, the order can get scrambled. Second, line breaks from the original often survive as hard breaks in the pasted text, so a paragraph falls apart into many short lines. For a quote or a short passage, cleaning that up by hand is fine; for a whole book, it is not.

Extract text from a PDF with an online tool

Online tools do the work for you: upload the file, get the text as a file or right in the browser, done. That is convenient when you only occasionally need text from a PDF and do not want to install anything.

One point deserves attention: with many online tools, your file is uploaded to a server for processing. For non-sensitive documents, that is no problem. If the PDF contains confidential content such as contracts, applications, or internal reports, local processing is the better choice. Our guide on removing PDF metadata explains how to check what else travels inside a file before you pass it on.

Extract text from a PDF on the command line: pdftotext

If you need text from PDFs regularly, a small command-line tool goes much further. The best known is pdftotext from the Poppler package, available on Linux, macOS, and Windows. A single command is enough:

pdftotext document.pdf output.txt

Afterwards, the entire text of the PDF is available as a text file, page by page. The -layout option additionally tries to preserve the original layout approximately, which helps with tables and columns. The advantage over copy and paste: the process is repeatable and can be automated for many files without opening each one individually.

Extract text from a PDF with Python

For your own scripts or larger numbers of files, Python is the most flexible solution. The libraries pypdf and pdfplumber read a PDF's text directly. A short example with pypdf:

from pypdf import PdfReader
reader = PdfReader("document.pdf")
text = "\n".join(page.extract_text() or "" for page in reader.pages)

That puts the text of all pages into one variable, ready for further processing: searching, counting, writing to a database, or using it as the basis for an analysis. pdfplumber is additionally useful when tables matter, because it recognises table cell structure better. Both libraries only work with PDFs that already have a text layer. For scanned pages, you need OCR first, as described in the next section.

Why extracted text often looks messy

When the result does not look like the original, it is almost always down to how text is stored in PDFs. A PDF describes where each character sits on the page, but not necessarily the logical order in which the words are read. Typical consequences:

  • Columns get read across: Text from the left column mixes with the right one, because the file stores the characters in a different order than the eye reads them.
  • Words are split at line ends: Hyphens from the original stay in the extracted text, so one word appears as two fragments.
  • Tables lose their structure: Without visible lines, a table's text collapses into a simple sequence of words and numbers.
  • Footnotes land mid-text: Footnotes and page numbers appear where they are stored in the file, not at the end of the page.

That is not a bug in the tool; it is a property of the format. For further processing as plain text, it is usually unproblematic. If you need the exact layout, convert the PDF into an editable format instead, or work directly in the PDF.

Scanned PDFs: OCR first, then extract

A scanned PDF contains no text layer, only images of the pages. Copying, pdftotext, and Python libraries find no text in it, because there is none to find. In this case, optical character recognition (OCR) must first read the letters from the images and create a text layer.

The best-known free solution for this is Tesseract, an open-source text recognition engine that supports many languages. The quality of the result depends heavily on the source material: a clean scan at good resolution produces much better text than a skewed, blurry photo of a page. Handwriting is generally recognised unreliably by OCR. After recognition, the text can be extracted like from any other PDF, using any of the methods in this guide.

Which method fits which case?

  • One-off, short passage: Copy and paste in a PDF reader, then a quick clean-up.
  • Occasional, whole documents: An online tool; for confidential content, prefer a local solution.
  • Regular or many files: pdftotext on the command line, or a Python script with pypdf or pdfplumber.
  • Scanned PDFs: OCR first, for example with Tesseract, then one of the methods above.
  • Layout must be preserved: Extracting text is the wrong approach. Edit the PDF itself instead, for example with our edit PDF tool, which adds and changes text on pages.

Frequently asked questions

Why can I not copy text from my PDF? Then the PDF almost certainly has no text layer. That is typical of scanned documents or PDFs created from images. Only text recognition (OCR) creates the text you can then extract.

Is formatting preserved when extracting? No. Extracted text is plain text without fonts, colours, or layout. If you need formatting, convert the PDF into an editable format instead of just pulling the text out.

Does this work with password-protected PDFs? Only if you first open the PDF with the password and save it unprotected. Protected files release their text to no tool while the protection is in place.

Is extracted text error-free? For PDFs with a text layer, the text is generally exact, apart from the ordering and hyphenation issues described above. For scanned sources, the error rate depends on scan quality. For important documents, always proofread the result against the original.

What is the difference from converting to Word? Extracting gives you plain text. Converting to Word additionally preserves some formatting, such as paragraphs and headings. For pure text analysis, extracting is enough; for further editing as a document, converting is better.