diff --git a/.gitignore b/.gitignore index b26da2e1..ad618018 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ venv/ bin/ include/ lib/ +pip-selfcheck.json +pyvenv.cfg diff --git a/ocrmypdf/main.py b/ocrmypdf/main.py index e9224795..74a2a44e 100755 --- a/ocrmypdf/main.py +++ b/ocrmypdf/main.py @@ -642,7 +642,12 @@ def tesseract_ocr_and_render_pdf( pdfinfo, pdfinfo_lock): - input_image = next(ii for ii in input_files if ii.endswith('.png')) + input_image = next((ii for ii in input_files if ii.endswith('.png')), '') + input_pdf = next((ii for ii in input_files if ii.endswith('.pdf'))) + if not input_image: + # Skipping this page + re_symlink(input_pdf, output_file) + return args_tesseract = [ 'tesseract', @@ -662,8 +667,6 @@ def tesseract_ocr_and_render_pdf( log.error(stderr) except TimeoutError: p.kill() - - input_pdf = next(ii for ii in input_files if ii.endswith('.pdf')) log.info("Tesseract - page timed out") re_symlink(input_pdf, output_file) diff --git a/tests/resources/multipage.pdf b/tests/resources/multipage.pdf new file mode 100644 index 00000000..4fd395fe Binary files /dev/null and b/tests/resources/multipage.pdf differ diff --git a/tests/test_main.py b/tests/test_main.py index 0b383f57..9fd0735a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -134,7 +134,7 @@ def test_force_ocr(): def test_skip_ocr(): - out = check_ocrmypdf('graph_ocred.pdf', 'test_skip.pdf', '-s') + check_ocrmypdf('graph_ocred.pdf', 'test_skip.pdf', '-s') def check_ocr_timeout(renderer): @@ -155,3 +155,15 @@ def test_skip_big(): pdfinfo = pdf_get_all_pageinfo(out) assert pdfinfo[0]['has_text'] == False + +def check_maximum_options(renderer): + check_ocrmypdf( + 'multipage.pdf', 'test_multipage%s.pdf' % renderer, + '-d', '-c', '-i', '-g', '-f', '-k', '--oversample', '300', + '--skip-big', '10', '--title', 'Too Many Weird Files', + '--author', 'py.test', '--pdf-renderer', renderer) + + +def test_maximum_options(): + yield check_maximum_options, 'hocr' + yield check_maximum_options, 'tesseract'