Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix escaping when extracting text using OCR #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/docsplit/text_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def extract_from_ocr(pdf, pages)
escaped_tiff = ESCAPE[tiff]
run "MAGICK_TMPDIR=#{tempdir} OMP_NUM_THREADS=2 gm convert -despeckle #{MEMORY_ARGS} #{OCR_FLAGS} #{escaped_pdf} #{escaped_tiff} 2>&1"
#if the user says don't do orientation detection or the plugin is not installed, set psm to 0
run "tesseract #{escaped_tiff} #{base_path} -l #{@language} #{psm} 2>&1"
run "tesseract #{escaped_tiff} #{ESCAPE[base_path]} -l #{@language} #{psm} 2>&1"
clean_text(base_path + '.txt') if @clean_ocr
end
ensure
Expand Down
9 changes: 7 additions & 2 deletions test/unit/test_extract_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ def test_password_protected
end
end

def test_name_escaping_while_extracting_text
def test_name_escaping_while_extracting_text_into_pages
Docsplit.extract_text('test/fixtures/PDF file with spaces \'single\' and "double quotes".pdf', :pages => 'all', :output => OUTPUT)
assert Dir["#{OUTPUT}/*.txt"].length == 2
end


def test_name_escaping_while_extracting_text_using_ocr
Docsplit.extract_text('test/fixtures/PDF file with spaces \'single\' and "double quotes".pdf', :ocr => true, :output => OUTPUT)
assert Dir["#{OUTPUT}/*.txt"].length == 1
end

def test_orientation_detected_ocr_extraction
if Docsplit::DEPENDENCIES[:osd]
pages = 1..4
Expand Down