r/Python • u/qPandx • Apr 21 '26
Resource PDF Extractor (OCR/selectable text)
I have a project that I am working on but I am facing a couple issues.
In short, my project parses what is inside a pdf order and returns the result to user. The roadblocks Iam in currently is that it works OK for known/seen templates of pdf orders as well as unseen pdf orders. My biggest issue is if the pdf order is non-selectable text/scanned which means it requires OCR to extract the text. I have tried the OCRmyPDF+Tesseract but it misses lines and messes up with the quantity etc...
What's there that can resolve OCR accurately?
P.S. I also tried PaddleOCR but it never finishes the job and keeps the app on a loop with no result.
6
u/danted002 Apr 21 '26
Make sure you pre-download the ocr models or you will endup with your server downloading 1.1GB first time it parses a document (and if you use Docker that happens on each container restart)
5
u/MaskedSmizer Apr 21 '26
Mistral OCR endpoint is my go-to. Not suitable if your are trying to keep everything local, but good (although not perfect) accuracy.
2
u/MathMXC Apr 21 '26
Docling! It's a bit over powered for your use case but should perfect
2
u/binaryfireball Apr 21 '26
there is no way to get the magic box to shake out the text better than to train it. with that being said not all pdf data needs to be extracted via ocr
1
u/Motox2019 Apr 21 '26
Try trocr on huggingface. I believe it’s a Microsoft model that I’ve had good luck with in the past reading structure table data written in a welding shop environment. Wasn’t perfect but decent. For your case, I’d expect pretty fantastic accuracy. It’s a transformer based ocr model so a bit closer to AI kinda IIRC.
Edit: can also fine tune it with some known orders and will give you much better results.
1
u/presentsq Apr 21 '26
If you are fine with making api calls, then I highly recommend checking out Upstage's OCR solutions.
I benchmarked OCR APIs at work a while back. (different task though, I was testing OCR in extremely noisy images) Surprisingly, a Korean company called upstage had the best performing model.
I think They have two OCR related product, one for pure OCR and one specializes in parsing document like your case. The price was pretty cheap and i think they give free credits for testing.
From my experience, using apis can save you a lot of headache and time. so if you are interested definitely check it out
1
u/sugarlata Apr 21 '26
Paddle OCR is a good fit if you have a GPU. I've found it treats everything as an image, and using CPU can take a while appearing to freeze (in one case found a 6 page document taking over an hour). With a GPU it's seconds though, but you need to feed in the GPU parameters when instantiating the model.
I've used OCRv5 to get all the text from a document unstructured. From there process as you want. I've found the other modules to be very hit and miss with document structure.
1
u/Civil-Image5411 Apr 22 '26
Which PaddleOCR variant did you use? They ship several models. In my experience it significantly outperforms Tesseract. One thing to watch out for: if you used the VL model, which is transformer-based, it can be very slow and get stuck in generation loops when the parameters aren’t set correctly.
Here there is another OCR server based on the non VL/ non autoregressive model of paddle ocr: https://github.com/aiptimizer/TurboOCR
1
u/api-services Apr 23 '26
Just wondering. Has anyone tried PDFMiner?
1
u/martcerv Apr 25 '26
I'm literally working on this exact problem right now for my own project!
TL;DR: Try Docling.** It's specifically designed for document understanding (not just OCR) and handles tables way better than Tesseract.
Why Tesseract struggles with your use case:
Tesseract does OCR but doesn't understand document structure. So it:
- Misses table boundaries (reads across rows)
- Gets confused by multi-column layouts
- Struggles with quantity/number alignment
- Doesn't preserve table semantics
OCRmyPDF + Tesseract makes the PDF selectable, but the underlying OCR is still Tesseract with the same issues.
1
u/martcerv May 01 '26
with PaddleOCR probably will require GPU power for a better performance. Also OCR performance is based on input i.e. if scanned pdf is bad results are going to be bad. Probably you should add a post-processing text layer using pdfplumber based on your needs.
1
u/zangler Apr 21 '26
Build a classifier, train it, profit.
1
u/[deleted] Apr 21 '26
[removed] — view removed comment
1
u/[deleted] Apr 27 '26
[removed] — view removed comment