diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index 4965145e..fa47ba5e 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -7,7 +7,7 @@ OCRmyPDF uses `semantic versioning `_. v4.5.2 ====== -- Fix issue #147, unpaper loses DPI information, which affects PDF rendering with ``--pdf-renderer tess4`` +- Fix issue #147. ``--pdf-renderer tess4 --clean`` will produce an oversized page containing the original image in the bottom left corner, due to loss DPI information. - Make "using Tesseract 4.0" warning less ominous - Set up machinery for homebrew OCRmyPDF tap diff --git a/ocrmypdf/exec/ghostscript.py b/ocrmypdf/exec/ghostscript.py index 748cc27b..dca504d8 100644 --- a/ocrmypdf/exec/ghostscript.py +++ b/ocrmypdf/exec/ghostscript.py @@ -2,12 +2,32 @@ # © 2015 James R. Barlow: github.com/jbarlow83 from tempfile import NamedTemporaryFile -from subprocess import Popen, PIPE, STDOUT, check_call +from subprocess import Popen, PIPE, STDOUT, check_call, CalledProcessError, \ + check_output from shutil import copy +from functools import lru_cache from . import get_program from ..pdfa import SRGB_ICC_PROFILE +@lru_cache(maxsize=1) +def version(): + args_gs = [ + get_program('gs'), + '--version' + ] + try: + version = check_output( + args_gs, close_fds=True, universal_newlines=True, + stderr=STDOUT) + except CalledProcessError as e: + print("Could not find Ghostscript executable on system PATH.", + file=sys.stderr) + raise MissingDependencyError from e + + return version.strip() + + def rasterize_pdf(input_file, output_file, xres, yres, raster_device, log, pageno=1): with NamedTemporaryFile(delete=True) as tmp: diff --git a/tests/test_main.py b/tests/test_main.py index 8cf06a08..730a1609 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -12,6 +12,7 @@ import PyPDF2 as pypdf from ocrmypdf.exceptions import ExitCode from ocrmypdf import leptonica from ocrmypdf.pdfa import file_claims_pdfa +from ocrmypdf.exec import ghostscript check_ocrmypdf = pytest.helpers.check_ocrmypdf @@ -172,6 +173,10 @@ def test_preserve_metadata(spoof_tesseract_noop, output_type, @pytest.mark.skipif( pytest.helpers.is_macos() and pytest.helpers.running_in_travis(), reason="save Travis the trouble of installing poppler") +@pytest.mark.xfail( + ghostscript.version() == '9.21', + reason="gs 9.21 has a regression that affects this" + ) @pytest.mark.parametrize("output_type", [ 'pdfa', 'pdf' ]) @@ -191,7 +196,7 @@ def test_override_metadata(spoof_tesseract_noop, output_type, resources, '--output-type', output_type, env=spoof_tesseract_noop) - assert p.returncode == ExitCode.ok + assert p.returncode == ExitCode.ok, err pdf = str(outpdf)