Live data from Hacker News

Ask HN: What is the best method for turning a scanned book as a PDF into text?

news.ycombinator.com

91–100 of 122 posts

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#91

I did this very recently for a 19th century book in German with occasionally some Greek. The method that produces the highest level of accuracy I've found is to use ImageMagick to extract each page as a image, then send each image file to Claude Sonnet (encoded as base64) with a simple user prompt like "Transcribe the complete text from this image verbatim with no additional commentary or explanations". The whole thi…

> a 19th century book

If you're dealing with public domain material, you can just upload to archive.org. They'll OCR the whole thing and make it available to you and everyone else. (If you got it from archive.org, check the sidebar for the existing OCR files.)

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#93
post #75

Earlier quoted context omitted.

There’s GPT4, then GPT4o (o for Omni, as in multi modal) and then GPT o1 (chain of thought / internal reasoning) then o3 (because o2 is a stadium in London that I guess is very litigious about its trademark?), o3-mini is the latest but yes optimized to be faster and cheaper

Which one is the smartest, and most knowledgeable? (Like least likely to make up facts)

4o is going to be better for a straight up factual question

(But eg I asked it about something Martin Short / John Mulaney said on SNL and it needed 2 prompts to get the correct answer..... the first answer wasn't making anything up it was just reasonably misinterpreting something)

It also has web search which will be more accurate if the pages it reads are good (it uses bing search, so if possible provide your own links and forcibly enable web search)

Similarly the latest Anthropic Claude Sonnet model (it's the new Sonnet 3.5 as of ~Oct) is very good.

The idea behind o3 mini is that it only knows as much as 4o mini (the names suck, we know) but it will be able to consider its initial response and edit it if it doesn't meet the original prompt's criteria

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#94
post #91

I did this very recently for a 19th century book in German with occasionally some Greek. The method that produces the highest level of accuracy I've found is to use ImageMagick to extract each page as a image, then send each image file to Claude Sonnet (encoded as base64) with a simple user prompt like "Transcribe the complete text from this image verbatim with no additional commentary or explanations". The whole thi…

> a 19th century book If you're dealing with public domain material, you can just upload to archive.org. They'll OCR the whole thing and make it available to you and everyone else. (If you got it from archive.org, check the sidebar for the existing OCR files.)

I did try the full text OCR from archive.org, but unfortunately the error rate is too high. Here are some screenshots to show what I mean:

- Original book image: https://imgur.com/a8KxGpY

- OCR from archive.org: https://imgur.com/VUtjiON

- Output from Claude: https://imgur.com/keUyhjR

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#95
I haven’t seen anyone else mention this tool yet, but I’ve found great accuracy and flexibility with [OCRmyPDF](https://github.com/ocrmypdf/OCRmyPDF). It (usually) detects and fixes page rotation, and works quite well on slanted text or A | B pages in regards to copying and formatting. I believe it uses tesseract in the background, but using it is very simple and it has the just works factor.

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#96

I did this very recently for a 19th century book in German with occasionally some Greek. The method that produces the highest level of accuracy I've found is to use ImageMagick to extract each page as a image, then send each image file to Claude Sonnet (encoded as base64) with a simple user prompt like "Transcribe the complete text from this image verbatim with no additional commentary or explanations". The whole thi…

Do you have a rough estimate of what the price per page was for this?

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#97
post #91

I did this very recently for a 19th century book in German with occasionally some Greek. The method that produces the highest level of accuracy I've found is to use ImageMagick to extract each page as a image, then send each image file to Claude Sonnet (encoded as base64) with a simple user prompt like "Transcribe the complete text from this image verbatim with no additional commentary or explanations". The whole thi…

> a 19th century book If you're dealing with public domain material, you can just upload to archive.org. They'll OCR the whole thing and make it available to you and everyone else. (If you got it from archive.org, check the sidebar for the existing OCR files.)

Maybe I've just had back luck, but their OCR butchered some of the books I've tried to get

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#98
post #91

Earlier quoted context omitted.

> a 19th century book If you're dealing with public domain material, you can just upload to archive.org. They'll OCR the whole thing and make it available to you and everyone else. (If you got it from archive.org, check the sidebar for the existing OCR files.)

I did try the full text OCR from archive.org, but unfortunately the error rate is too high. Here are some screenshots to show what I mean: - Original book image: https://imgur.com/a8KxGpY - OCR from archive.org: https://imgur.com/VUtjiON - Output from Claude: https://imgur.com/keUyhjR

Ah, yeah, that's not uncommon. I was operating on an assumption, based on experience seeing language models make mistakes, that the two approaches would be within an acceptable range of each other for your texts, plus the idea that it's better to share the work than not.

Note if you're dealing with a work (or edition) that cannot otherwise be found on archive.org, though, then if you do upload it, you are permitted as the owner of that item to open up the OCRed version and edit it. So an alternative workflow might be better stated:

1. upload to archive.org

2. check the OCR results

3. correct a local copy by hand or use a language model to assist if the OCR error rate is too high

4. overwrite the autogenerated OCR results with the copy from step 3 in order to share with others

(For those unaware and wanting to go the collaborative route, there is also the Wikipedia-adjacent WMF project called Wikisource. It has the upside of being more open (at least in theory) than, say, a GitHub repo—since PRs are not required for others to get their changes integrated. One might find, however, it to be less open in practice, since it is inhabited by a fair few wikiassholes of the sort that folks will probably be familiar with from Wikipedia.)

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#99
The article below compares 5 tools for a slightly different but close enough use case (more complex pdf than just running text). It concludes:

"Surprisingly, ChatGPT-4o gave the best Markdown output overall. Asking a multimodal LLM to simply convert a document to Markdown might be the best option if slow processing speed and token cost are not a problem."

https://ai.gopubby.com/benchmarking-pdf-to-markdown-document...

Re: Ask HN: What is the best method for turning a scanned book as a PDF into text?

#100
post #44

Copyright issues aside (e.g. if your thing is public domain), the galaxy-brain approach is to upload your raw scanned PDF to the Internet Archive (archive.org), fill in the appropriate metadata, wait about 24 hours for their post-upload format-conversion tasks to run automatically, and then download the size-optimized and OCR-ized PDF from them. I've done this with a few documents from the French and Spanish national…

Last time I checked a few months ago, LLMs were more accurate than the OCR that the archive is using. The web archive version is/was not using context to figure out that for example “in the garden was a trge” should be “in the garden was a tree”. LLMs depending on the prompt do this.

Perhaps. My perhaps-curmudgeonly take on that is that it sounds a bit like "Xerox scanners/photocopiers randomly alter numbers in scanned documents" ( https://news.ycombinator.com/item?id=29223815 ). I'd much rather deal with "In the garden was a trge" than "In the garden was a tree," for example, if what the page actually said was "In the garden was a tiger." That said, of course you're right that context is useful for OCRing. See for example https://history.stackexchange.com/questions/50249/why-does-n...

Another, perhaps-leftpaddish argument is that by outsourcing the job to archive.org I'm allowing them to worry about the "best" way to OCR things, rather than spending my own time figuring it out. Wikisource, for example, seems to have gotten markedly better at OCRing pages over the past few years, and I assume that's because they're swapping out components behind the scenes.

Post reply on HN