Tools,

Gemma 4 OCR: turn thinking off first

1,950 of 1,955

words right, 10 pages, 31.7 s

Run it on a scan

Run it on a scan

Ollama takes images, not PDFs. Take the scan's JPEGs out, then send each page with thinking off:

ollama pull gemma4:e4b
pdfimages -j scan.pdf page
for f in page-*.jpg; do
  ollama run --think=false gemma4:e4b "Transcribe all the text in this image exactly as written, in reading order. Output only the text: no comments, no Markdown. ./$f"
done > scan.txt

That gave the 1,950 words above, on a Mac GPU. Plain gemma4 is the same model as gemma4:e4b.

Thinking is on by default

33.2 s thinking off, 1,947 words

98.2 s thinking on, 1,941 words

Ollama turns thinking on by default for every Gemma 4 size. On 9 of 10 pages, e4b wrote 1,851 to 3,404 characters of reasoning first.

With ollama run, that reasoning lands in your file: 574 words out for a 202-word page. --hidethinking only hides it: on one page, 7.7 s against 3.0 s with --think=false. In the API, send "think": false.

Which size: e4b, or 12b

Words right, of 1,955 on 10 book pages
Model Words Time Download
e2b 1,921 29.5 s 7.5 GB
e4b 1,947 33.2 s 9.5 GB
12b 1,952 42.4 s 7.7 GB
26b 1,944 37.7 s 16 GB
31b 1,865 84.4 s 19 GB

Tesseract 5.5.4 on the same pages: 1,878 in 20.1 s.

31b reads fine. It copies the printer's spaces before ? and ; (family ? Not) and inside quotes. This strict count marks those words wrong. With those spaces taken out, 31b gets 1,949 and 26b 1,953.

A PDF gets an error, or nothing

Send a PDF to the API as an image and it stops:

{"error":"media expansion produced no tokens"}

ollama run with a PDF path exits 0 with no page text. With thinking off, it printed the file path back. With it on, 710 words of reasoning that it cannot see the file.

pdfimages -j gave back all 10 scan JPEGs byte for byte.

The prompt hardly matters

"Extract the text from this image." got 1,949 words. My longer prompt got 1,947. The default temperature, 1, got 1,949.

No run added a preface, a comment or a Markdown fence.

Scanned PDF to Markdown, no model download

Our Actor takes the PDF itself and returns Markdown, on CPU. Its code read 1,879 words of these pages: fewer than Gemma 4, with no 9.5 GB download and no GPU.

It costs $0.006 a scanned page.

How I tested it
  • Pages: 10 proofread pages of 2 books on English Wikisource, 1920 px JPEGs, 1,955 words. The same pages as my ONLYOFFICE test.
  • Ollama 0.40.16 from GitHub. Gemma 4 e2b, e4b, 12b, 26b and 31b from the Ollama library, nvfp4, Apache-2.0.
  • One page a request, as it is. Temperature 0 and thinking off, unless the text says so. The loop on top used the defaults with --think=false.
  • Apple Silicon Mac GPU, lowest priority. Times are rough: model downloads ran during some runs.
  • Score: true words found in order.
  • The Actor row is its own code from git, build 0.1.65, on the 10 page images with its default inputs. Not a run on Apify.
What I did not test
  • Other languages, photos, tables and handwriting.
  • Gemma 4 in llama.cpp, LM Studio or Transformers.
  • Image size settings, Windows and Linux.
Sources

Two ways to skip the work

Run it yourself. Our Apify Actor turns scanned PDFs and images into Markdown, tables included.

Try the Actor

Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.

Get one page free

Questions people ask

Can Gemma 4 do OCR?

Yes. In Ollama, gemma4:e4b read 1,950 of 1,955 words of a 10-page book scan with thinking off. Tesseract read 1,878 of the same pages.

Which Gemma 4 size is best for OCR?

On my scan, 12b read the most words: 1,952. e4b read 1,947 and was faster. e2b lost 34 words. 31b was the slowest, at 84.4 s.

Why is Gemma 4 OCR slow in Ollama?

Thinking is on by default. With it on, e4b took 98.2 s for 10 pages. With thinking off, 33.2 s.

Can Gemma 4 read a PDF?

Not in Ollama: the API answers "media expansion produced no tokens". Take the pages out as images with pdfimages -j, then send each one.