PDF to Text

Published Updated

Save the text layer of every PDF page as one UTF-8 .txt file, with a blank line between pages. Pages that are only pictures, like most scans, come out empty.

Words in, layout out

This tool copies the characters a PDF draws on its pages into a plain text file, and nothing else: no fonts, images, tables or columns. Each page's lines are joined with spaces, and pages are separated by one blank line. The download is UTF-8, the encoding the browser uses for text put into a file (MDN, Blob constructor), so text in any alphabet survives if the PDF describes its characters properly.

That last condition matters more than people expect. A PDF stores character codes, not letters, and a reader has to map each code to Unicode. ISO 32000-1, section 9.10 lists the ways a file can provide that mapping, a ToUnicode table in the font or a standard Latin encoding, and says that when they are missing there is no way to know what a code represents. Such files come out garbled here and in other text extractors.

What three test files turned into

The same reading code the tool uses, run on test PDFs from this site's tool checks:

Test PDFResulting .txt
A one-page shopping list, one item per lineOne line: Shopping list Bread Milk Eggs Nails, 40 mm Wood glue, then the last sentence; 109 bytes
A two-page report: a heading, two paragraphs, a small table and two bullet points on page 1Two blocks, one per page; heading, table rows and bullets all run into the page 1 block; 742 bytes
Three pages that are photos only, like a scanFour bytes: the blank lines between empty pages

The third row is the one to watch. A download of a few bytes means the PDF has no text layer, not that extraction failed, and the result card then says No text was found.

Columns, tables, scripts and hidden text: what comes out

The site's own PDF to Text component was run on generated PDFs in Google Chrome 156, Chromium 153 (Playwright build, not Google Chrome), Firefox 155 and Playwright's WebKit build (not the Safari app). All four produced the same text, character for character.

Test pageWhat the .txt held
Two columns of three lines, the left column stored firstL1, L2, L3, then R1, R2, R3, all on one line with spaces between them
A three-row table: Item, Qty, PriceItem Qty Price Apples 12 3.40 Pears 7 2.10, cells and rows separated by single spaces
A line turned 90 degrees near the right marginThe words in their place in the line, complete; the warning about text near the page border still appeared, although nothing was missing
Glyphs for the ffi and fi ligatures, Arabic stored right to left as most PDF writers place it, and Chinese and Japanese charactersoffice fish field سلام عالم 東京 你好: plain letters for the ligatures and the Arabic in reading order; 33 characters, 49 bytes of UTF-8
White text on white, and invisible text of the kind OCR software lays over a scanBoth, like any other text on the page
A filled form field, a comment and a web linkNone of them: their values are not part of the page text
A page that is only a photoAn empty file, and the note No text was found
A PDF encrypted with AES-256Refused as soon as it is added: This PDF is password-protected

Long documents take well under a second in Chrome. Time from Extract Text to the download link, for dense Letter pages of about 5,100 characters each:

PDFText fileChrome 156Chromium 153Firefox 155WebKit build
40 pages, 93,278 bytes204,946 characters0.14 s0.17 s0.32 s0.28 s
200 pages, 464,937 bytes1,024,812 characters0.45 s0.47 s0.99 s0.78 s

Getting the text out of a PDF

  1. Step 1

    Add one PDF

    Its pages are counted first. Any encrypted PDF is refused at this point, even one that opens without a password.

  2. Step 2

    Press Extract Text

    pdf.js reads the characters each page draws, in the order the file stores them, and joins the lines of a page with spaces.

  3. Step 3

    Download the .txt

    It takes the PDF's name with .txt at the end. A note appears when a line touches the page edge, where letters can drop out.

When another tool keeps more structure

Plain text suits searching, scripts and word counts. For anything else, one of these keeps more of the document:

  • PDF to Word splits paragraphs where the layout shows them. On the same test report it found eight paragraphs on page 1 where this tool gives one.
  • PDF to Markdown marks headings, tables and page breaks.
  • PDF to Excel puts table rows and columns into spreadsheet cells.

PDF to text: what people ask

Can it read a scanned PDF?

Only if the scan already carries a hidden text layer, which some scanning software adds. A page that is just a picture gives nothing, because the tool reads stored text and does not recognise letters in images.

Why is each page one long paragraph?

Line breaks inside a page become spaces so that wrapped sentences stay whole. A break survives only where the PDF's text stream holds an empty line, and most files have none. PDF to Word starts paragraphs from the layout instead.

Why do I get strange symbols instead of words?

The fonts in that PDF do not say which Unicode character each glyph stands for, so any extractor has to guess. If copying the same passage in a PDF viewer gives the same symbols, the file itself lacks the mapping and no text tool will fix it.

What does the warning about a page edge mean?

pdf.js leaves out characters that start outside the visible page. When a line runs right up to an edge, the tool cannot tell whether a letter was lost there, so it asks you to compare that line with the original.

Are hyphenated line breaks joined back together?

No. A word split as exam- at the end of one line and ple on the next comes out as exam- ple, with the hyphen and a space. PDF to Markdown has an option that joins such words.

Does it work on a password-protected PDF?

No. Any encryption stops the file when it is added, including a PDF whose only protection is a ban on copying. If you are allowed to remove that, run it through Unlock PDF first and add the result.

Does it work with Arabic, Chinese or other scripts?

Yes, when the PDF maps its characters to Unicode. In the test above, Arabic stored right to left came out in reading order, Chinese and Japanese characters came through, and ligature glyphs became plain letters (office, fish, field). The file is UTF-8, so those 33 characters took 49 bytes.

Will text I cannot see end up in the file?

Yes. White text on a white background and the invisible text layer that OCR software adds to scans are extracted like visible text. Check the .txt before sharing it if the PDF came from someone else.

Are form field values and comments included?

No. In the test above, a filled text field, a comment and a link address were all missing from the output in every browser. Only the text drawn on the page itself is read.

How long does a 200-page PDF take?

Under a second in our test: 0.45 s in Chrome 156 and 0.99 s in Firefox 155 for 200 dense pages that gave 1,024,812 characters. Each page becomes one paragraph, separated by a blank line.

Related Tools