I am using Apache Tika Parser to parse PDF files into text. Some PDFs could contain scanned documents. Apache Tika uses Tesseract to recognize a text into images. But there is no jar library with Tesseract and user should install Tesseract as independent application in operation system. How can I use Tesseract from Apache Tika without installing Tesseract? I tried to add tesseract folder to classpath and configure like below:
TesseractOCRConfig config = new TesseractOCRConfig();
config.setTesseractPath("tesseract");
config.setTessdataPath("tesseract/tessdata");
PDFParserConfig pdfConfig = new PDFParserConfig();
pdfConfig.setOcrStrategy(PDFParserConfig.OCR_STRATEGY.OCR_AND_TEXT_EXTRACTION);
ParseContext parseContext = new ParseContext();
parseContext.set(PDFParserConfig.class, pdfConfig);
but I got:
org.apache.commons.io.IOExceptionWithCause: Unable to end a page
at org.apache.tika.parser.pdf.AbstractPDF2XHTML.endPage(AbstractPDF2XHTML.java:428)
at org.apache.tika.parser.pdf.PDF2XHTML.endPage(PDF2XHTML.java:162)
at org.apache.pdfbox.text.PDFTextStripper.processPage(PDFTextStripper.java:393)
at org.apache.tika.parser.pdf.PDF2XHTML.processPage(PDF2XHTML.java:147)
at org.apache.pdfbox.text.PDFTextStripper.processPages(PDFTextStripper.java:319)
at org.apache.pdfbox.text.PDFTextStripper.writeText(PDFTextStripper.java:266)
at org.apache.tika.parser.pdf.PDF2XHTML.process(PDF2XHTML.java:117)
... 43 common frames omitted
Caused by: org.apache.tika.exception.TikaException: Tesseract is not available. Please set the OCR_STRATEGY to NO_OCR or configure Tesseract correctly
at org.apache.tika.parser.pdf.AbstractPDF2XHTML.doOCROnCurrentPage(AbstractPDF2XHTML.java:321)
at org.apache.tika.parser.pdf.AbstractPDF2XHTML.endPage(AbstractPDF2XHTML.java:418)
... 49 common frames omitted
also I tried to use tess4j library, which consumes File, but I need to parse from InputStream without caching into hard drive. Could anyone please help me to configure Apache Tika and Tesseract?
BufferedImage
, so from yourInputStream
:BufferedImage image = ImageIO.read(inputStream);
– Bundlejava.lang.IllegalArgumentException: image == null
for the pdf file – Chromolithography