@ Override public List < OCRResult > createDocumentsWithResults ( String [ ] filenames , String [ ] outputbases , List < ITesseract . RenderedFormat > formats , int pageIteratorLevel ) throws TesseractException { if ( filenames . length != outputbases . length ) { throw new RuntimeException ( "The two arrays must match in length." ) ; } init ( ) ; setTessVariables ( ) ; List < OCRResult > results = new ArrayList < OCRResult > ( ) ; try { for ( int i = 0 ; i < filenames . length ; i ++ ) { File inputFile = new File ( filenames [ i ] ) ; File imageFile = null ; try { // if PDF, convert to multi-page TIFF imageFile = ImageIOHelper . getImageFile ( inputFile ) ; TessResultRenderer renderer = createRenderers ( outputbases [ i ] , formats ) ; int meanTextConfidence = createDocuments ( imageFile . getPath ( ) , renderer ) ; List < Word > words = meanTextConfidence > 0 ? getRecognizedWords ( pageIteratorLevel ) : new ArrayList < Word > ( ) ; results . add ( new OCRResult ( meanTextConfidence , words ) ) ; TessDeleteResultRenderer ( renderer ) ; } catch ( Exception e ) { // skip the problematic image file logger . warn ( e . getMessage ( ) , e ) ; } finally { // delete temporary TIFF image for PDF if ( imageFile != null && imageFile . exists ( ) && imageFile != inputFile && imageFile . getName ( ) . startsWith ( "multipage" ) && imageFile . getName ( ) . endsWith ( ImageIOHelper . TIFF_EXT ) ) { imageFile . delete ( ) ; } } } } finally { dispose ( ) ; } return results ; }
Creates documents with OCR results for given renderers at specified page iterator level .