Tools,

OCR a large PDF: 431 pages, tested

8.9 min

for OCRmyPDF to read 431 pages

Get the command

OCRmyPDF fastest, Tesseract lightest

One 1907 book scan from Wikisource: 431 pages, 70 MB, no text layer.

Time and peak memory for the whole book
Way Time Memory
OCRmyPDF, 2 jobs 8.9 min 485 MB
OCRmyPDF, 2 jobs, plain PDF out 8.7 min 464 MB
Tesseract, one process 12.8 min 72 MB
Our Actor's code, 3 pages at once 14.4 min 1,540 MB
Our Actor's code, 1 page at once 44.0 min 1,165 MB

Every run read every page with no errors, at low priority on a Mac with an M5 Max.

How we ran it
  • The book: The Life and Work of Richard John Seddon, by James Drummond. The PDF is on Wikimedia Commons, public domain: one JPEG on each A4 page, most of them 1,250 pixels tall.
  • OCRmyPDF 17.13.0 and Tesseract 5.5.4 with the English model. No Ghostscript: OCRmyPDF made its PDF/A itself.
  • Our Actor's code is the committed folder, run on the Mac with its own Python packages and models. It draws each page at 300 dpi and checks its turn and tilt.
  • Memory is the peak of all the run's processes added together, read every half second. Shared memory counts more than once.
  • Tesseract and both OCRmyPDF runs shared the Mac with the Actor's one-page run, and with other jobs. Our runs used 3 busy cores or less.

Same words, if you read them in order

Wikisource volunteers proofread the book. We scored each way on the 229 pages whose proofread text is plain prose: 87,885 words.

Proofread words found in order
Way Words Share
OCRmyPDF file, read with pdftotext -raw 86,913 98.9%
Tesseract's text file 86,893 98.9%
Our Actor's Markdown 86,863 98.8%
Tesseract's PDF, read with pdftotext 86,857 98.8%
OCRmyPDF file, read with pdftotext 85,911 97.8%

The OCR read the same words. The gap is the copy step: pdftotext put some lines of OCRmyPDF's file out of order. The -raw flag keeps the order the OCR wrote.

70 MB in, 70.6 MB out

File Size
The scan 70.0 MB
OCRmyPDF, PDF/A 70.6 MB
OCRmyPDF, plain PDF 70.6 MB
Tesseract 72.0 MB

The text layer is small. OCRmyPDF's optimizer left the JPEG pages as they were.

Tesseract's PDF sizes each page to its picture at about 70 dpi. Most pages come out 17.9 inches tall, not A4.

The command for a big scan

ocrmypdf -j 2 big.pdf big-ocr.pdf
pdftotext -raw big-ocr.pdf big.txt

-j sets how many pages OCRmyPDF reads at once. Leave it out to use every core. To install OCRmyPDF, see how to make a PDF searchable.

Add --output-type pdf to skip the PDF/A step. It saved only 12 seconds here.

Without OCRmyPDF: Tesseract alone

This works when each page is one JPEG, as in this scan. Up to 1,000 pages, ls keeps the pages in order. It uses one core and little memory.

pdfimages -j big.pdf p
ls p-*.jpg > list.txt
tesseract list.txt big-ocr -l eng pdf txt

You get big-ocr.pdf and big-ocr.txt, one form feed between pages.

On Apify, a big book needs time

Our Actor's default Apify run has 1 GB of memory, a quarter of a CPU core, and a one-hour timeout.

Estimate for this book at the Actor's defaults
Seconds a page in our 10-page runs of other files 13.3 to 52.6
431 pages at that pace 1.6 to 6.3 hours
Page price for the 428 pages with text $2.57

Our latest runs were at the slow end. Near the timeout the Actor saves what it read, and you pay only for that.

For a big book, raise Memory and Timeout, or use the Pages field, like 1-100. Each 4 GB adds a core and a page at a time, up to 4.

Scanned PDF to text, no install

Run it yourself. Our Apify Actor turns a scanned PDF into Markdown or text. $0.006 a scanned page, up to 100 MB a file. On the free plan, 20 pages a run.

Try the Actor

Questions people ask

How long does OCR take for a 400-page PDF?

Our 431-page scan took 8.9 minutes with OCRmyPDF on 2 cores, and 12.8 minutes with Tesseract on one core. Both ran at low priority on a Mac with an M5 Max.

Do I have to split a large PDF first?

Not for OCRmyPDF or Tesseract. Both read all 431 pages in one go. On Apify, read a big book in parts with the Pages field, or raise the run's timeout.

How much memory does OCR of a large PDF need?

OCRmyPDF with 2 jobs peaked at 485 MB on this book. Tesseract alone, one page at a time, peaked at 72 MB.

Does OCR make the PDF bigger?

Barely. The 70.0 MB scan came out at 70.6 MB from OCRmyPDF and 72.0 MB from Tesseract. The text layer is small next to the page images.

Is there a file size limit?

OCRmyPDF and Tesseract hit no limit on this 70 MB file. Our Apify Actor takes files up to 100 MB and 5,000 pages, and reads 1,000 pages a run unless you raise Max pages per run.