Ask HN: How to OCR a PDF and preserve whitespace?
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.
17 comments
[ 0.23 ms ] story [ 41.9 ms ] threadhttps://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...
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/
In my experience it works amazingly well with columns / tabulated content.
But if you think about space and font widtgs, youll realize nontrivial. Fonts are often variable sizes and table alignments are often left, right or center aligned.
A more general tool ive used is PaddleOCR
https://apps.apple.com/us/app/super-pdf-ocr/id6479674248
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.
https://pypi.org/project/pdfminer.six/
There also is an older version PDF XChange viewer, that has the ability to do the same thing, although it is presented as "viewer".
1: https://github.com/ocrmypdf/OCRmyPDF/
LLMWhisperer has some nice tooling where they can fall back to OCR as well forcing text extraction from scanned documents as well as documents that have the text preserved as text.