Skip to content

Commit 5b2ec86

Browse files
committed
first crack at psm flag
1 parent b9fecdd commit 5b2ec86

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

lib/docsplit.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,28 @@ module Docsplit
1818

1919
DEPENDENCIES = {:java => false, :gm => false, :pdftotext => false, :pdftk => false, :pdftailor => false, :tesseract => false}
2020

21+
osd = false
22+
2123
# Check for all dependencies, and note their absence.
2224
dirs = ENV['PATH'].split(File::PATH_SEPARATOR)
2325
DEPENDENCIES.each_key do |dep|
2426
dirs.each do |dir|
2527
if File.executable?(File.join(dir, dep.to_s))
2628
DEPENDENCIES[dep] = true
29+
if dep.to_s == 'tesseract' #if the tesseract dependency is found
30+
val = %x[ #{'tesseract --list-langs'} 2>&1 >/dev/null ] #check for the osd plugin.
31+
if val =~ /\bosd\b/ #osd will be listed in tesseract --listlangs
32+
osd = true
33+
end
34+
end
2735
break
2836
end
2937
end
3038
end
3139

32-
# Raise an ExtractionFailed exception when the PDF is encrypted, or otherwise
40+
DEPENDENCIES[:osd] = osd
41+
42+
# Raise an ExtractionFailed exception when the PDF is encrypted, or otherwise
3343
# broke.
3444
class ExtractionFailed < StandardError; end
3545

lib/docsplit/command_line.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def parse_options
101101
opts.on('-r', '--rolling', 'generate images from each previous image') do |r|
102102
@options[:rolling] = true
103103
end
104+
opts.on('-nod', '--no-orientation-detection', 'turn off automatic orientation detection in tesseract') do |r|
105+
@options[:nod] = true
106+
end
104107
opts.on_tail('-v', '--version', 'display docsplit version') do
105108
puts "Docsplit version #{Docsplit::VERSION}"
106109
exit

lib/docsplit/text_extractor.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def extract_from_ocr(pdf, pages)
7474
tiff = "#{tempdir}/#{@pdf_name}.tif"
7575
escaped_tiff = ESCAPE[tiff]
7676
run "MAGICK_TMPDIR=#{tempdir} OMP_NUM_THREADS=2 gm convert -despeckle #{MEMORY_ARGS} #{OCR_FLAGS} #{escaped_pdf} #{escaped_tiff} 2>&1"
77-
run "tesseract #{escaped_tiff} #{base_path} -l #{@language} 2>&1"
77+
psm = "-psm 1"
78+
if @nod
79+
psm = ""
80+
end
81+
run "tesseract #{escaped_tiff} #{base_path} -l #{@language} #{psm} 2>&1"
7882
clean_text(base_path + '.txt') if @clean_ocr
7983
end
8084
ensure

0 commit comments

Comments
 (0)