From 4cb488d0fc4cde780cfeaa9b57e79993d0964f62 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 8 Jan 2026 15:12:35 -0800 Subject: [PATCH] Skip speculative PDF/A when --pdfa-image-compression is set When the user explicitly sets --pdfa-image-compression to something other than 'auto', skip the speculative PDF/A conversion and use Ghostscript instead. The speculative conversion (using pikepdf + verapdf) doesn't apply image compression settings, so Ghostscript is required to honor the user's compression preference. --- src/ocrmypdf/_pipeline.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ocrmypdf/_pipeline.py b/src/ocrmypdf/_pipeline.py index 60c238f6..56b6e788 100644 --- a/src/ocrmypdf/_pipeline.py +++ b/src/ocrmypdf/_pipeline.py @@ -949,11 +949,24 @@ def try_speculative_pdfa(input_pdf: Path, context: PdfContext) -> Path | None: """ from ocrmypdf._exec import verapdf + options = context.options + + # Skip speculative conversion if user requested specific image compression, + # since that requires Ghostscript to apply + gs_opts = getattr(options, 'ghostscript', None) + if gs_opts is not None: + compression = getattr(gs_opts, 'pdfa_image_compression', 'auto') + if compression != 'auto': + log.debug( + 'Skipping speculative PDF/A: --pdfa-image-compression=%s requires ' + 'Ghostscript', + compression, + ) + return None + if not verapdf.available(): log.debug('verapdf not available, skipping speculative PDF/A conversion') return None - - options = context.options output_file = context.get_path('speculative_pdfa.pdf') try: