Module: Asposeocrjava

Defined in:
lib/asposeocrjava.rb,
lib/asposeocrjava/version.rb,
lib/asposeocrjava/OCR/detectreading.rb,
lib/asposeocrjava/OCR/multipagetiff.rb,
lib/asposeocrjava/OCR/recognizetext.rb,
lib/asposeocrjava/OCR/correctspellings.rb,
lib/asposeocrjava/OCR/detecttextblocks.rb,
lib/asposeocrjava/OCR/loadimagefromurl.rb,
lib/asposeocrjava/OMR/setmarkthreshold.rb,
lib/asposeocrjava/OMR/setimageresolution.rb,
lib/asposeocrjava/OMR/detectimageresolution.rb,
lib/asposeocrjava/OCR/applycorrectionfilters.rb,
lib/asposeocrjava/OCR/ignorenontextualblocks.rb,
lib/asposeocrjava/OMR/extractomrdatafromimage.rb,
lib/asposeocrjava/OCR/readpartinformationoftext.rb,
lib/asposeocrjava/OCR/extracttextfrompartofimage.rb,
lib/asposeocrjava/OCR/gettextparthierarchyoftext.rb,
lib/asposeocrjava/OCR/workwithdifferentlanguages.rb,
lib/asposeocrjava/OCR/recognizewhitelistedcharacters.rb

Defined Under Namespace

Modules: ApplyCorrectionFilters, CorrectSpellings, DetectImageResolution, DetectReading, DetectTextBlocks, ExtractOmrDataFromImage, ExtractTextFromPartOfImage, GetTextPartHierarchyOfText, IgnoreNonTextualBlocks, LoadImageFromUrl, MultipageTiff, ReadPartInformationOfText, RecognizeText, RecognizeWhiteListedCharacters, SetImageResolution, SetMarkThreshold, WorkWithDifferentLanguages

Constant Summary collapse

VERSION =
'0.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.aspose_ocr_configObject

Returns the value of attribute aspose_ocr_config.



9
10
11
# File 'lib/asposeocrjava.rb', line 9

def aspose_ocr_config
  @aspose_ocr_config
end

Class Method Details

.configure_aspose_ocr(config) ⇒ Object



67
68
69
# File 'lib/asposeocrjava.rb', line 67

def self.configure_aspose_ocr config
  Asposeocrjava.aspose_ocr_config = config
end

Instance Method Details

#initialize_aspose_ocrObject



12
13
14
15
16
17
18
19
# File 'lib/asposeocrjava.rb', line 12

def initialize_aspose_ocr
  aspose_jars_dir = Asposeocrjava.aspose_ocr_config ? Asposeocrjava.aspose_ocr_config['jar_dir'] : nil  
  aspose_license_path = Asposeocrjava.aspose_ocr_config ? Asposeocrjava.aspose_ocr_config['license_path'] : nil
  jvm_args = Asposeocrjava.aspose_ocr_config ? Asposeocrjava.aspose_ocr_config['jvm_args'] : nil
  
  load_aspose_jars(aspose_jars_dir, jvm_args)
  load_aspose_license(aspose_license_path)
end

#input_file(file) ⇒ Object



50
51
52
# File 'lib/asposeocrjava.rb', line 50

def input_file(file)
  Rjb::import('java.io.FileInputStream').new(file)
end

#load_aspose_jars(aspose_jars_dir, jvm_args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/asposeocrjava.rb', line 31

def load_aspose_jars(aspose_jars_dir, jvm_args)
  if aspose_jars_dir && File.exist?(aspose_jars_dir)
    jardir = File.join(aspose_jars_dir, '**', '*.jar')
  else
    jardir = File.join(File.dirname(File.dirname(__FILE__)), 'jars', '**', '*.jar')
  end

  if jvm_args
    args = jvm_args.split(' ') << '-Djava.awt.headless=true'
    logger = Logger.new(STDOUT)
    logger.level = Logger::DEBUG
    logger.debug("JVM args : #{args}")
    Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=args)
  else
    Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=['-Djava.awt.headless=true'])
  end

end

#load_aspose_license(aspose_license_path) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/asposeocrjava.rb', line 21

def load_aspose_license(aspose_license_path)
  if aspose_license_path && File.exist?(aspose_license_path)
    set_license(File.join(aspose_license_path))
  else
    logger = Logger.new(STDOUT)
    logger.level = Logger::WARN
    logger.warn('Using the non licensed aspose jar. Please specify path to your aspose license directory in config/aspose.yml file!')
  end
end

#set_license(aspose_license_file) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/asposeocrjava.rb', line 54

def set_license(aspose_license_file)
  begin
    fstream = input_file(aspose_license_file)
    license = Rjb::import('com.aspose.api.License').new()
    license.setLicense(fstream)
  rescue Exception => ex
    logger = Logger.new(STDOUT)
    logger.level = Logger::ERROR
    logger.error("Could not load the license file : #{ex}")
    fstream.close() if fstream
  end
end