TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

26 pointsby GirkovArpa12 months ago
I have some rather large PDFs that need to be transcribed, but every service I try has some minor but deal-breaking flaw.<p>Either they don&#x27;t support PDFs this large (hundreds of pages), are just really bad at English OCR, or, most commonly, don&#x27;t preserve whitespace correctly.<p>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.<p>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.

13 comments

eigenvalue12 months ago
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:<p><a href="https:&#x2F;&#x2F;apps.apple.com&#x2F;us&#x2F;app&#x2F;super-pdf-ocr&#x2F;id6479674248" rel="nofollow">https:&#x2F;&#x2F;apps.apple.com&#x2F;us&#x2F;app&#x2F;super-pdf-ocr&#x2F;id6479674248</a>
评论 #40618887 未加载
评论 #40618878 未加载
sargstuff12 months ago
Not sure if a multi-step is ok, but convert pdf to image format such as png, use AI to recognize &#x27;tabular blocks&#x27;, convert pdf to &#x27;text format&#x27; with tabular blocks as embeddable image to preserve spacing.<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;3203790&#x2F;parsing-pdf-files-especially-with-tables-with-pdfbox" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;3203790&#x2F;parsing-pdf-file...</a><p><a href="https:&#x2F;&#x2F;excalibur-py.readthedocs.io&#x2F;en&#x2F;master&#x2F;" rel="nofollow">https:&#x2F;&#x2F;excalibur-py.readthedocs.io&#x2F;en&#x2F;master&#x2F;</a><p><a href="https:&#x2F;&#x2F;ledgerbox.io&#x2F;blog&#x2F;extract-tables-with-tesseract-ocr" rel="nofollow">https:&#x2F;&#x2F;ledgerbox.io&#x2F;blog&#x2F;extract-tables-with-tesseract-ocr</a><p><a href="https:&#x2F;&#x2F;www.johnsnowlabs.com&#x2F;extract-tabular-data-from-pdf-in-spark-ocr&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.johnsnowlabs.com&#x2F;extract-tabular-data-from-pdf-i...</a><p>bit more in-depth review : <a href="https:&#x2F;&#x2F;dev.to&#x2F;upsilon_it&#x2F;how-to-extract-tabular-data-from-pdf-part-1-i3" rel="nofollow">https:&#x2F;&#x2F;dev.to&#x2F;upsilon_it&#x2F;how-to-extract-tabular-data-from-p...</a>
tacostakohashi12 months ago
Did you try textract? <a href="https:&#x2F;&#x2F;aws.amazon.com&#x2F;textract&#x2F;" rel="nofollow">https:&#x2F;&#x2F;aws.amazon.com&#x2F;textract&#x2F;</a><p>In my experience it works amazingly well with columns &#x2F; tabulated content.
bdowling12 months ago
Many of the free or cheap OCR services are based on the free, open-source Tesseract OCR.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tesseract-ocr&#x2F;tesseract&#x2F;">https:&#x2F;&#x2F;github.com&#x2F;tesseract-ocr&#x2F;tesseract&#x2F;</a><p>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.
constantinum12 months ago
Do give LLMWhisperer[1] a try. It does a good job preserving the layout for the most part — but one cannot escape PDF hell.<p>Try LLMwhisperer Playground[2] with your documents; there is no need for any setup.<p>Extracting multi-column layout example - <a href="https:&#x2F;&#x2F;imgur.com&#x2F;roYmv0I" rel="nofollow">https:&#x2F;&#x2F;imgur.com&#x2F;roYmv0I</a><p>[1] <a href="https:&#x2F;&#x2F;llmwhisperer.unstract.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;llmwhisperer.unstract.com&#x2F;</a> [2] <a href="https:&#x2F;&#x2F;pg.llmwhisperer.unstract.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pg.llmwhisperer.unstract.com&#x2F;</a>
评论 #40620873 未加载
cpach12 months ago
Can you use ImageMagick to split the columns into single files…? E.g. if the columns are the same on every page, you can feed the coordinates to ImageMagick. Then do OCR on each of those files.
cyanydeez12 months ago
Tabula works for tables.<p>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.<p>A more general tool ive used is PaddleOCR
sandreas12 months ago
Your use case seems very specific. I personally am very happy with ocrmypdf[1], which is free and puts an invisible text layer into the pdf. However, since it is free, I&#x27;m pretty sure it cannot compete with the commercial solutions you tried.<p>There also is an older version PDF XChange viewer, that has the ability to do the same thing, although it is presented as &quot;viewer&quot;.<p>1: <a href="https:&#x2F;&#x2F;github.com&#x2F;ocrmypdf&#x2F;OCRmyPDF&#x2F;">https:&#x2F;&#x2F;github.com&#x2F;ocrmypdf&#x2F;OCRmyPDF&#x2F;</a>
brianjking12 months ago
LLMWhisperer from Zipstack at <a href="https:&#x2F;&#x2F;llmwhisperer.unstract.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;llmwhisperer.unstract.com&#x2F;</a> or <a href="https:&#x2F;&#x2F;github.com&#x2F;VikParuchuri&#x2F;surya">https:&#x2F;&#x2F;github.com&#x2F;VikParuchuri&#x2F;surya</a> will do a good job for you.<p>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.
shevis12 months ago
Google’s OCR service is reliably accurate and can handle large documents (up to 20MB) <a href="https:&#x2F;&#x2F;cloud.google.com&#x2F;vision&#x2F;docs&#x2F;ocr" rel="nofollow">https:&#x2F;&#x2F;cloud.google.com&#x2F;vision&#x2F;docs&#x2F;ocr</a>
4oo412 months ago
I&#x27;ve had really good results with Python&#x27;s pdfminer.six, it&#x27;s also very easy to use.<p><a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;pdfminer.six&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;pdfminer.six&#x2F;</a>
halotrope12 months ago
we have an internal api at markets.sh for ingesting large financial reports and newspaper data. solves this exact problem. i‘ll be happy to give you test access. drop me an email at max at markets.sh
rthnbgrredf12 months ago
You could try this one here: <a href="https:&#x2F;&#x2F;github.com&#x2F;madnight&#x2F;pdf-layout-text-stripper">https:&#x2F;&#x2F;github.com&#x2F;madnight&#x2F;pdf-layout-text-stripper</a>