From 6910c48b8113ace3ddc14392c87c938a2b1d7624 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Mon, 6 Dec 2021 14:44:34 -0800 Subject: [PATCH] Fix test_outputtype_none on Windows and cleanup docs --- docs/cookbook.rst | 3 +++ src/ocrmypdf/_validation.py | 6 +++--- tests/test_main.py | 5 ++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/cookbook.rst b/docs/cookbook.rst index f4eada82..cc5f3cae 100644 --- a/docs/cookbook.rst +++ b/docs/cookbook.rst @@ -104,6 +104,9 @@ This produces a file named "output.pdf" and a companion text file named because of options like ``--skip-big`` or ``--tesseract-timeout``, those pages will not be in the sidecar. + If you don't want to generate the output PDF, use ``--output-type=none`` to + avoid generating one. Set the output filename to ``-`` (i.e. redirect to stdout). + To extract all text from a PDF, whether generated from OCR or otherwise, use a program like Poppler's ``pdftotext`` or ``pdfgrep``. diff --git a/src/ocrmypdf/_validation.py b/src/ocrmypdf/_validation.py index b6022dd2..a69514f1 100644 --- a/src/ocrmypdf/_validation.py +++ b/src/ocrmypdf/_validation.py @@ -78,11 +78,11 @@ def check_options_output(options): "`--pdf-renderer auto` (the default) to avoid this issue." ) - if options.output_type == 'none' and options.output_file != os.devnull: + if options.output_type == 'none' and options.output_file not in (os.devnull, '-'): raise BadArgsError( - "Since you specified `--pdf-renderer none`, the output file " + "Since you specified `--output-type none`, the output file " f"{options.output_file} cannot be produced. Set the output file to " - f"{os.devnull} to suppress this message." + f"`-` to suppress this message." ) lossless_reconstruction = False diff --git a/tests/test_main.py b/tests/test_main.py index f308b1f3..c9b8ad51 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -916,9 +916,9 @@ def test_outputtype_none_bad_setup(resources, outpdf): def test_outputtype_none(resources, outtxt): - p, _out, err = run_ocrmypdf( + p, out, err = run_ocrmypdf( resources / 'trivial.pdf', - os.devnull, + '-', '--output-type=none', '--sidecar', outtxt, @@ -926,4 +926,3 @@ def test_outputtype_none(resources, outtxt): 'tests/plugins/tesseract_noop.py', ) assert p.returncode == ExitCode.ok - assert outtxt.exists()