public class TesseractOCRParser extends AbstractParser implements Initializable
TesseractOCRConfig
object and pass it through a
ParseContext. Tesseract-ocr must be installed and on system path or the path
to its root folder must be provided:
TesseractOCRConfig config = new TesseractOCRConfig();
//Needed if tesseract is not on system path
config.setTesseractPath(tesseractFolder);
parseContext.set(TesseractOCRConfig.class, config);
Constructor and Description |
---|
TesseractOCRParser() |
Modifier and Type | Method and Description |
---|---|
void |
checkInitialization(InitializableProblemHandler problemHandler) |
TesseractOCRConfig |
getDefaultConfig() |
java.util.Set<MediaType> |
getSupportedTypes(ParseContext context)
Returns the set of media types supported by this parser when used
with the given parse context.
|
boolean |
hasTesseract(TesseractOCRConfig config) |
void |
initialize(java.util.Map<java.lang.String,Param> params)
no-op
|
void |
parse(java.awt.Image image,
org.xml.sax.ContentHandler handler,
Metadata metadata,
ParseContext context) |
void |
parse(java.io.InputStream stream,
org.xml.sax.ContentHandler handler,
Metadata metadata,
ParseContext parseContext)
Parses a document stream into a sequence of XHTML SAX events.
|
void |
parseInline(java.io.InputStream stream,
XHTMLContentHandler xhtml,
ParseContext parseContext,
TesseractOCRConfig config)
Use this to parse content without starting a new document.
|
void |
parseInline(java.io.InputStream stream,
XHTMLContentHandler xhtml,
TesseractOCRConfig config)
|
void |
setApplyRotation(boolean applyRotation) |
void |
setColorspace(java.lang.String colorspace) |
void |
setDensity(int density) |
void |
setDepth(int depth) |
void |
setEnableImageProcessing(int enableImageProcessing) |
void |
setFilter(java.lang.String filter) |
void |
setImageMagickPath(java.lang.String imageMagickPath) |
void |
setLanguage(java.lang.String language) |
void |
setMaxFileSizeToOcr(long maxFileSizeToOcr) |
void |
setMinFileSizeToOcr(long minFileSizeToOcr) |
void |
setOutputType(java.lang.String outputType) |
void |
setPageSegMode(java.lang.String pageSegMode) |
void |
setPreserveInterwordSpacing(boolean preserveInterwordSpacing) |
void |
setResize(int resize) |
void |
setTessdataPath(java.lang.String tessdataPath) |
void |
setTesseractPath(java.lang.String tesseractPath) |
void |
setTimeout(int timeout) |
parse
public java.util.Set<MediaType> getSupportedTypes(ParseContext context)
Parser
getSupportedTypes
in interface Parser
context
- parse contextpublic boolean hasTesseract(TesseractOCRConfig config)
public void parse(java.awt.Image image, org.xml.sax.ContentHandler handler, Metadata metadata, ParseContext context) throws java.io.IOException, org.xml.sax.SAXException, TikaException
java.io.IOException
org.xml.sax.SAXException
TikaException
public void parse(java.io.InputStream stream, org.xml.sax.ContentHandler handler, Metadata metadata, ParseContext parseContext) throws java.io.IOException, org.xml.sax.SAXException, TikaException
Parser
The given document stream is consumed but not closed by this method. The responsibility to close the stream remains on the caller.
Information about the parsing context can be passed in the context parameter. See the parser implementations for the kinds of context information they expect.
parse
in interface Parser
stream
- the document stream (input)handler
- handler for the XHTML SAX events (output)metadata
- document metadata (input and output)parseContext
- parse contextjava.io.IOException
- if the document stream could not be readorg.xml.sax.SAXException
- if the SAX events could not be processedTikaException
- if the document could not be parsedpublic void parseInline(java.io.InputStream stream, XHTMLContentHandler xhtml, TesseractOCRConfig config) throws java.io.IOException, org.xml.sax.SAXException, TikaException
stream
- inputstreamxhtml
- handlerconfig
- TesseractOCRConfig to use for this parsejava.io.IOException
org.xml.sax.SAXException
TikaException
public void parseInline(java.io.InputStream stream, XHTMLContentHandler xhtml, ParseContext parseContext, TesseractOCRConfig config) throws java.io.IOException, org.xml.sax.SAXException, TikaException
stream
- inputstreamxhtml
- handlerconfig
- TesseractOCRConfig to use for this parsejava.io.IOException
org.xml.sax.SAXException
TikaException
public void initialize(java.util.Map<java.lang.String,Param> params) throws TikaConfigException
initialize
in interface Initializable
params
- params to use for initializationTikaConfigException
public void checkInitialization(InitializableProblemHandler problemHandler) throws TikaConfigException
checkInitialization
in interface Initializable
problemHandler
- if there is a problem and no
custom initializableProblemHandler has been configured
via Initializable parameters,
this is called to respond.TikaConfigException
@Field public void setTesseractPath(java.lang.String tesseractPath)
@Field public void setTessdataPath(java.lang.String tessdataPath)
@Field public void setLanguage(java.lang.String language)
@Field public void setPageSegMode(java.lang.String pageSegMode)
@Field public void setMaxFileSizeToOcr(long maxFileSizeToOcr)
@Field public void setMinFileSizeToOcr(long minFileSizeToOcr)
@Field public void setTimeout(int timeout)
@Field public void setOutputType(java.lang.String outputType)
@Field public void setPreserveInterwordSpacing(boolean preserveInterwordSpacing)
@Field public void setEnableImageProcessing(int enableImageProcessing)
@Field public void setImageMagickPath(java.lang.String imageMagickPath)
@Field public void setDensity(int density)
@Field public void setDepth(int depth)
@Field public void setColorspace(java.lang.String colorspace)
@Field public void setFilter(java.lang.String filter)
@Field public void setResize(int resize)
@Field public void setApplyRotation(boolean applyRotation)
public TesseractOCRConfig getDefaultConfig()
Copyright © 2010 - 2020 Adobe. All Rights Reserved