Package com.itextpdf.pdfocr.tesseract4
Class AbstractTesseract4OcrEngine
java.lang.Object
com.itextpdf.pdfocr.tesseract4.AbstractTesseract4OcrEngine
- All Implemented Interfaces:
-
IOcrEngine,IProductAware
- Direct Known Subclasses:
-
Tesseract4ExecutableOcrEngine,Tesseract4LibOcrEngine
public abstract class AbstractTesseract4OcrEngine extends Object implements IOcrEngine, IProductAware
The implementation of
IOcrEngine.
This class provides possibilities to perform OCR, to read data from input files and to return contained text in the required format. Also, there are possibilities to use features of "tesseract" (optical character recognition engine for various operating systems).
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractTesseract4OcrEngine(Tesseract4OcrEngineProperties tesseract4OcrEngineProperties) Creates a newTesseract4OcrEnginePropertiesinstance based on anotherTesseract4OcrEnginePropertiesinstance (copy constructor). -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateTxtFile(List<File> inputImages, File txtFile) Performs OCR using providedIOcrEnginefor the given list of input images and saves output to a text file using provided path.voidcreateTxtFile(List<File> inputImages, File txtFile, OcrProcessContext ocrProcessContext) Performs OCR using providedIOcrEnginefor the given list of input images and saves output to a text file using provided path.doImageOcr(File input) Reads data from the provided input image file and returns retrieved data in the format described below.doImageOcr(File input, OcrProcessContext ocrProcessContext) Reads data from the provided input image file and returns retrieved data in the format described below.final StringdoImageOcr(File input, OutputFormat outputFormat) Reads data from the provided input image file and returns retrieved data as string.final StringdoImageOcr(File input, OutputFormat outputFormat, OcrProcessContext ocrProcessContext) Reads data from the provided input image file and returns retrieved data as string.voiddoTesseractOcr(File inputImage, File outputFile, OutputFormat outputFormat) Performs tesseract OCR for the first (or for the only) image page.voiddoTesseractOcr(File inputImage, File outputFile, OutputFormat outputFormat, OcrProcessContext ocrProcessContext) Performs tesseract OCR for the first (or for the only) image page.final StringGets list of languages concatenated with "+" symbol to a string in format required by tesseract.Gets the container with meta info.com.itextpdf.commons.actions.data.ProductDataGets object containing information about the product.Gets properties forAbstractTesseract4OcrEngine.Identifies type of current OS and return it (win, linux).booleanChecks whether tagging is supported by the OCR engine.booleanChecks current os type.final voidsetTesseract4OcrEngineProperties(Tesseract4OcrEngineProperties tesseract4OcrEngineProperties) Sets properties forAbstractTesseract4OcrEngine.voidvalidateLanguages(List<String> languagesList) Validates list of provided languages and checks if they all exist in given tess data directory.
-
Constructor Details
-
AbstractTesseract4OcrEngine
Creates a newTesseract4OcrEnginePropertiesinstance based on anotherTesseract4OcrEnginePropertiesinstance (copy constructor).- Parameters:
-
tesseract4OcrEngineProperties- the otherTesseract4OcrEnginePropertiesinstance
-
-
Method Details
-
doTesseractOcr
Performs tesseract OCR for the first (or for the only) image page.- Parameters:
-
inputImage- input imageFile -
outputFile- output file for the result for the first page -
outputFormat- selectedOutputFormatfor tesseract
-
doTesseractOcr
public void doTesseractOcr(File inputImage, File outputFile, OutputFormat outputFormat, OcrProcessContext ocrProcessContext) Performs tesseract OCR for the first (or for the only) image page.- Parameters:
-
inputImage- input imageFile -
outputFile- output file for the result for the first page -
outputFormat- selectedOutputFormatfor tesseract -
ocrProcessContext- ocr process context
-
createTxtFile
Performs OCR using providedIOcrEnginefor the given list of input images and saves output to a text file using provided path.- Specified by:
-
createTxtFilein interfaceIOcrEngine - Parameters:
-
inputImages-Listof images to be OCRed -
txtFile- file to be created
-
createTxtFile
public void createTxtFile(List<File> inputImages, File txtFile, OcrProcessContext ocrProcessContext) Performs OCR using providedIOcrEnginefor the given list of input images and saves output to a text file using provided path.- Specified by:
-
createTxtFilein interfaceIOcrEngine - Parameters:
-
inputImages-Listof images to be OCRed -
txtFile- file to be created -
ocrProcessContext- ocr process context
-
getTesseract4OcrEngineProperties
Gets properties forAbstractTesseract4OcrEngine.- Returns:
-
set properties
Tesseract4OcrEngineProperties
-
setTesseract4OcrEngineProperties
public final void setTesseract4OcrEngineProperties(Tesseract4OcrEngineProperties tesseract4OcrEngineProperties) Sets properties forAbstractTesseract4OcrEngine.- Parameters:
-
tesseract4OcrEngineProperties- set of propertiesTesseract4OcrEnginePropertiesforAbstractTesseract4OcrEngine
-
getLanguagesAsString
Gets list of languages concatenated with "+" symbol to a string in format required by tesseract.- Returns:
-
Stringof concatenated languages
-
doImageOcr
Reads data from the provided input image file and returns retrieved data in the format described below.- Specified by:
-
doImageOcrin interfaceIOcrEngine - Parameters:
-
input- input imageFile - Returns:
-
Mapwhere key isIntegerrepresenting the number of the page and value isListofTextInfoelements where eachTextInfoelement contains a word or a line and its 4 coordinates(bbox)
-
doImageOcr
public final Map<Integer,List<TextInfo>> doImageOcr(File input, OcrProcessContext ocrProcessContext) Reads data from the provided input image file and returns retrieved data in the format described below.- Specified by:
-
doImageOcrin interfaceIOcrEngine - Parameters:
-
input- input imageFile -
ocrProcessContext- ocr process context - Returns:
-
Mapwhere key isIntegerrepresenting the number of the page and value isListofTextInfoelements where eachTextInfoelement contains a word or a line and its 4 coordinates(bbox)
-
doImageOcr
public final String doImageOcr(File input, OutputFormat outputFormat, OcrProcessContext ocrProcessContext) Reads data from the provided input image file and returns retrieved data as string.- Parameters:
-
input- input imageFile -
outputFormat- returnOutputFormatresult -
ocrProcessContext- ocr process context - Returns:
-
OCR result as a
Stringthat is returned after processing the given image
-
doImageOcr
Reads data from the provided input image file and returns retrieved data as string.- Parameters:
-
input- input imageFile -
outputFormat- returnOutputFormatresult - Returns:
-
OCR result as a
Stringthat is returned after processing the given image
-
isWindows
public boolean isWindows()Checks current os type.- Returns:
- boolean true is current os is windows, otherwise - false
-
identifyOsType
Identifies type of current OS and return it (win, linux).- Returns:
-
type of current os as
String
-
validateLanguages
Validates list of provided languages and checks if they all exist in given tess data directory.- Parameters:
-
languagesList-Listof provided languages - Throws:
-
PdfOcrTesseract4Exception- if tess data wasn't found for one of the languages from the provided list
-
getMetaInfoContainer
Gets the container with meta info.- Specified by:
-
getMetaInfoContainerin interfaceIProductAware - Returns:
- the held meta info container
-
getProductData
public com.itextpdf.commons.actions.data.ProductData getProductData()Description copied from interface:IProductAwareGets object containing information about the product.- Specified by:
-
getProductDatain interfaceIProductAware - Returns:
- product data
-
isTaggingSupported
public boolean isTaggingSupported()Description copied from interface:IOcrEngineChecks whether tagging is supported by the OCR engine.- Specified by:
-
isTaggingSupportedin interfaceIOcrEngine - Returns:
-
trueif tagging is supported by the engine,falseotherwise
-