From 4d3b44d6dfe9c8639755914171ca17657c7e2eac Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 8 Dec 2016 16:19:15 -0800 Subject: [PATCH] ghostscript: cleanup harmless error message printed for overprint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redirect stderr->stdout to hopefully make GS output easier to work with overall, since the previous code didn’t seem to account for mixed used properly. --- ocrmypdf/ghostscript.py | 49 ++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/ocrmypdf/ghostscript.py b/ocrmypdf/ghostscript.py index ee1b5bad..f724ebad 100644 --- a/ocrmypdf/ghostscript.py +++ b/ocrmypdf/ghostscript.py @@ -2,7 +2,7 @@ # © 2015 James R. Barlow: github.com/jbarlow83 from tempfile import NamedTemporaryFile -from subprocess import Popen, PIPE, check_call +from subprocess import Popen, PIPE, STDOUT, check_call from shutil import copy from . import get_program from .pdfa import SRGB_ICC_PROFILE @@ -25,16 +25,13 @@ def rasterize_pdf(input_file, output_file, xres, yres, raster_device, log, input_file ] - p = Popen(args_gs, close_fds=True, stdout=PIPE, stderr=PIPE, + p = Popen(args_gs, close_fds=True, stdout=PIPE, stderr=STDOUT, universal_newlines=True) - stdout, stderr = p.communicate() - if stdout: - if 'error' in stdout: - log.error(stdout) # Ghostscript puts errors in stdout - else: - log.debug(stdout) - if stderr: - log.error(stderr) + stdout, _ = p.communicate() + if 'error' in stdout: + log.error(stdout) # Ghostscript puts errors in stdout + else: + log.debug(stdout) if p.returncode == 0: copy(tmp.name, output_file) @@ -60,24 +57,22 @@ def generate_pdfa(pdf_pages, output_file, log, threads=1): "-sOutputFile=" + gs_pdf.name, ] args_gs.extend(pdf_pages) - p = Popen(args_gs, close_fds=True, stdout=PIPE, stderr=PIPE, + p = Popen(args_gs, close_fds=True, stdout=PIPE, stderr=STDOUT, universal_newlines=True) - stdout, stderr = p.communicate() - if stdout: - if 'error' in stdout: - log.error(stdout) - elif 'overprint mode not set' in stdout: - # Unless someone is going to print PDF/A documents on a - # magical sRGB printer I can't see the removal of overprinting - # being a problem.... - log.debug( - "Ghostscript had to remove PDF 'overprinting' from the " - "input file to complete PDF/A conversion. " - ) - else: - log.debug(stdout) - if stderr: - log.error(stderr) + stdout, _ = p.communicate() + + if 'error' in stdout: + log.error(stdout) + elif 'overprint mode not set' in stdout: + # Unless someone is going to print PDF/A documents on a + # magical sRGB printer I can't see the removal of overprinting + # being a problem.... + log.debug( + "Ghostscript had to remove PDF 'overprinting' from the " + "input file to complete PDF/A conversion. " + ) + else: + log.debug(stdout) if p.returncode == 0: # Ghostscript does not change return code when it fails to create