Search code examples
slf4jtess4j

How to handle exception Unsupported image format from tess4j?


I'm trying to use tess4j to get a text from image, it's error:

"java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I/O package."

Although, I added JAI-imageio-core to dependencies.

File imageFile = new File("myFilePath");
    ITesseract instance = new Tesseract();
    try {
        String result = instance.doOCR(imageFile);
        return result;
    } catch (TesseractException e) {
        System.err.println(e.getMessage());
        return "Error while reading image";
    }

Solution

  • Had the same issue with payara, copy the jai image io lib to your java dir C:\ProgramFiles\Java\jdk {version}\jre\lib\ext

    This worked for me.

    Tested with Payara / Wildfly 11