B4J=true Group=Default Group ModulesStructureVersion=1 Type=Class Version=7 @EndOfDesignText@ private Sub Class_Globals Private fx As JFX Private locationOfFiles As String ' used by the inline java code Private init As Boolean = False End Sub 'Initializes the object. You must supply where the traineddata files are located. Public Sub Initialize(traineddataFileLocation As String) locationOfFiles = traineddataFileLocation init = True End Sub public Sub isInitialized As Boolean Return init End Sub ' do OCR on an image file pass full path to sub public Sub OcrFromFile(Filename As String) As String Return asJO(Me).RunMethod("getImgTextFromFile",Array(Filename)) End Sub ' do OCR on a the byte buffer public Sub OcrFromBuffer(Buffer() As Byte) As String Return asJO(Me).RunMethod("getImgTextFromBuffer",Array(Buffer)) End Sub private Sub asJO(o As JavaObject) As JavaObject Return o End Sub #if java import net.sourceforge.tess4j.*; import java.io.*; import java.nio.ByteBuffer; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; public String getImgTextFromFile(String imageLocation) { ITesseract instance = new Tesseract(); // this needs setting to where the traineddata files are instance.setDatapath(_locationoffiles); // read from globals in this class try { String imgText = instance.doOCR(new File(imageLocation)); return imgText; } catch (TesseractException e) { e.getMessage(); return "Error while reading image"; } } public String getImgTextFromBuffer(byte[] buf) { ITesseract instance = new Tesseract(); // this needs setting to where the traineddata files are instance.setDatapath(_locationoffiles); // reads from globals in this class try { BufferedImage img = ImageIO.read(new ByteArrayInputStream(buf)); String imgText = instance.doOCR(img); return imgText; } catch (IOException | TesseractException e) { e.getMessage(); return "Error while reading image"; } } #End If