Extract the text from a PDF as a .txt file
A PDF does not store sentences. It stores instructions to put letters at coordinates, and the reading order has to be reconstructed from where they landed — this does that and hands you a plain UTF-8 text file. If the document is a scan, there is nothing to reconstruct: the pages are pictures of words, not words, and the job stops and says so rather than giving you an empty file.
It cannot read a scan. A scanned or photographed page holds a picture of words rather than words, so there is nothing to extract; the OCR tool reports which pages are affected, and this deployment can report on OCR but not perform it.
How it works
- Choose the pages. All of them, or a range like 1-3,7 when you only want one section of a long report. Pages are read one at a time, so a range costs what it says.
- Decide how the page should be read. Leave ‘keep the layout’ off for ordinary prose. Turn it on for two-column papers and tables, where reading by position on the page beats reading in the order the file happens to store.
- Download the .txt. One UTF-8 text file named after the document. A note gives the character count and says how many pages had no text at all, which is the signal that part of the file is a scan.
What the options do
The form above lists the options this tool is running today, straight from the server. This is what they are for.
- Pages to read
- Which pages to extract, as 1-3,7 or ‘all’. Pages are read individually, so asking for three pages of a 900-page report costs three pages of work, and a page that defeats the reader can be named in the message instead of taking the whole job down.
- Keep the layout
- Two different reconstructions of reading order. Off, the default, follows the order the glyphs were written in — right for the great majority of documents, and it keeps a paragraph a paragraph. On, everything is sorted by its position on the page, which is what a two-column paper or a table needs and wrong for a document whose columns were drawn out of order. If the output reads as two sentences interleaved, run it again with this on.
- Mark where each page ends
- Puts a form feed — U+000C, what a page break has meant in a text file since the teletype — between pages. Most editors show it as a page break and every scripting language can split on it. Turned off, pages are separated by a blank line instead, which is friendlier if you are pasting the text into something else.
What this tool does not do
- It cannot read a scan. A scanned or photographed page holds a picture of words rather than words, so there is nothing to extract; the OCR tool reports which pages are affected, and this deployment can report on OCR but not perform it.
- Layout is not preserved as layout. Tables come out as lines of words, and columns stay columns only with the layout option on — and even then the alignment is approximate. PDF to Excel is the tool for tables.
- Headers, footers and page numbers are text like anything else, so they appear once per page in the output.
- It does not say where on the page each line was. Anything that needs coordinates needs a different tool.
- A PDF whose fonts carry no character information produces unreadable output, and nothing can fix that after the fact — the meaning was never in the file.
What happens to your file
The file is uploaded because PDF to text runs on our server rather than in the browser tab. It is kept for at most 2 hours and the result you download for 24 hours, then a scheduled job deletes both — a job has to be able to read the file while it runs, and you have to be able to retry a failed conversion without re-uploading. Neither needs longer.
Nothing about the contents is logged, and no one reads your documents. The retention page lists the same numbers the code enforces, and the privacy policy says who can reach the storage they sit in.
Questions
- My text file came back empty, or the tool said there was no text.
- The pages are pictures. That is what a scan, a photograph of a document or a fax looks like inside a PDF: an image of letters, with no letters behind it. The OCR tool will tell you which pages are affected — though on this deployment it reports rather than fixes, so the file would need to go through OCR software first.
- The columns have come out jumbled together.
- Turn on ‘keep the layout’ and run it again. That sorts everything by where it sits on the page instead of the order the PDF stored it in, which is what a two-column layout needs.
- What is the odd character between the pages?
- A form feed, U+000C — the standard page break in a plain text file. Editors show it as a break and scripts split on it. Turn off ‘mark where each page ends’ if you would rather have a blank line.
- Will the tables survive?
- Not as tables: a text file has no columns. The cells come out as words on a line, in a sensible order if you turn the layout option on. If you need the numbers in a spreadsheet, PDF to Excel finds the columns from the white space and writes CSV.
- What about accents, currency symbols and non-Latin scripts?
- The output is always UTF-8, so they survive. If they come out as rubbish, the problem is at the other end — an editor opening the file as a legacy code page — rather than in the extraction.