Live data from Hacker News

Ask HN: How to OCR a PDF and preserve whitespace?

news.ycombinator.com

1–10 of 18 posts

Ask HN: How to OCR a PDF and preserve whitespace?

#1
I have some rather large PDFs that need to be transcribed, but every service I try has some minor but deal-breaking flaw.

Either they don't support PDFs this large (hundreds of pages), are just really bad at English OCR, or, most commonly, don't preserve whitespace correctly.

The number one problem is whitespace when it comes to multiple columns (similar to newspapers). Either not putting any spaces between words, or when there are multiple columns of text, putting rows in the wrong order. If it was just a single page, this would still be useful, since I could fix it myself. But I have over 1000 pages.

I tried so many free services and trials that I just got charged for forgetting to cancel one (thanks to smallpdf.com for refunding my $12). Is OCR technology just not there yet when it comes to multiple-column pages? Yet, this does not seem to be an issue with newspapers.com, based on my experience using their text search feature. I would like to know what OCR software they are using.

Re: Ask HN: How to OCR a PDF and preserve whitespace?

#2
Not sure if a multi-step is ok, but convert pdf to image format such as png, use AI to recognize 'tabular blocks', convert pdf to 'text format' with tabular blocks as embeddable image to preserve spacing.

https://stackoverflow.com/questions/3203790/parsing-pdf-file...

https://excalibur-py.readthedocs.io/en/master/

https://ledgerbox.io/blog/extract-tables-with-tesseract-ocr

https://www.johnsnowlabs.com/extract-tabular-data-from-pdf-i...

bit more in-depth review : https://dev.to/upsilon_it/how-to-extract-tabular-data-from-p...

Re: Ask HN: How to OCR a PDF and preserve whitespace?

#3
Do give LLMWhisperer[1] a try. It does a good job preserving the layout for the most part — but one cannot escape PDF hell.

Try LLMwhisperer Playground[2] with your documents; there is no need for any setup.

Extracting multi-column layout example - https://imgur.com/roYmv0I

[1] https://llmwhisperer.unstract.com/ [2] https://pg.llmwhisperer.unstract.com/

Re: Ask HN: How to OCR a PDF and preserve whitespace?

#8
I’ve found that the built in OCR in the iPhone is just way better and more accurate than everything else out there. I’m talking about how if you have an image in your camera roll on the iPhone, you can select the text and copy it out. I had the idea to simply expose that service better so it could be applied to PDFs and made my first ever iPhone app that does this. It can easily handle hundreds of pages too. Only problem is that it’s an iPhone app so it can’t easily be included in a programmatic fashion, but if you’re only trying to convert a reasonable number of documents it’s worth a try— the accuracy is really good:

https://apps.apple.com/us/app/super-pdf-ocr/id6479674248

Re: Ask HN: How to OCR a PDF and preserve whitespace?

#9
Many of the free or cheap OCR services are based on the free, open-source Tesseract OCR.

https://github.com/tesseract-ocr/tesseract/

Those services usually do not expose all of the options. If you’re handy with shell scripts or Python, you can probably get better performance by hand-tuning options for your particular images. For example, if I recall there are page segmentation options to tell Tesseract to expect multi-column text. That alone might get you better performance than the automatic mode.

Re: Ask HN: How to OCR a PDF and preserve whitespace?

#10

I’ve found that the built in OCR in the iPhone is just way better and more accurate than everything else out there. I’m talking about how if you have an image in your camera roll on the iPhone, you can select the text and copy it out. I had the idea to simply expose that service better so it could be applied to PDFs and made my first ever iPhone app that does this. It can easily handle hundreds of pages too. Only pro…

Are you the guy that posted on x about using iphone device as OCR?
Post reply on HN