6

Has anybody attempted to extract text from a PDF using an OCR library and Java? What did you find to be the most reliable library for text extraction. Most of the approaches I've seen (tesseract, GOCR) are C libraries that would require some JNI code to be written.

I'm familiar with pdfbox, which is now an Apache incubator project at version 0.8.x, but it's text extraction isn't always accurate. I'm looking for an alternative approach that is somewhat more reliable.

I've not tried Asprise JavaPDF yet, in the process of trying that, but wanted to know more about the OCR approach (if it's possible).

Any help would be appreciated.

Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150

4 Answers4

7

If you have a text-based PDF, I'd strongly recommend PDFTextStream. It's not free, but licensing is reasonable, and it is much much better than PDFBox. PDFBox chokes on many PDF files which are generated by newer tools, and is not too consistent about PDFs it can handle. PDFTextStream handles any PDF I throw at it, including PDFs with embedded PNG images, which PDFBox can not do.

If you heckle the PDFTextStream folks to add OCR, they may listen up.

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Sam Barnum
  • 10,559
  • 3
  • 54
  • 60
  • Thanks, sounds good, pity about the price though... – Jonathan Holloway Apr 22 '09 at 19:28
  • 1
    Several years later, but now PDFTextStream has a free version (with a 1 Tread cap) – Markos Fragkakis May 21 '14 at 14:08
  • 1
    If the PDF is already text-based, why discuss OCR? Just use PDFBox, iText, PDFTextStream, or whatever to parse the text. OCR is for times when the PDF is an image, say from a scanner. If the PDF is a scanned image, neither PDFBox, iText, nor PDFTextStream will help you. – Don Cheadle Oct 21 '14 at 20:44
  • I have a Text-based PDF, the language is not English. When I read the text using PDFBox all the characters are messed up. So the only option left to try is OCR. Hence we need to discuss OCR. – Abhinav P Sep 20 '17 at 12:22
2

We use ABBYY FineReader Engine 11. They have java wrapper.

Pros:

  • It works great with all the languages (English, Russian, Uzbek etc) and doing real OCR (even if you have pdf without OCR they perform rendering at first and OCRing).

Cons:

  • It costs. You have to buy developer license and end-user license.

  • And it is EXTREMELY slow.

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Andrew
  • 21
  • 1
  • Thanks for answering and your honesty about the product. For some years, questions asking to recommend tools are off-topic, and answering them is considered 'not done'. (actually, the question should be deleted if it doesn't have any use any more) – Patrick Hofman Apr 08 '15 at 09:31
1

You can use Java wrappers of Tesseract - tesjeract or Tess4J - to perform OCR. However, for PDF, you'll need to convert to image (PNG or TIFF) first before feeding it to the OCR engine.

VietOCR calls Tesseract executable to perform the text extraction. It uses GhostScript to do PDF-to-image conversion.

nguyenq
  • 8,212
  • 1
  • 16
  • 16
1

If you want to extract OCR from text based PDF you may have to convert it to an image first.

Otávio Décio
  • 73,752
  • 17
  • 161
  • 228