From ee5acbe94eae866067b5a516bb4ae86739b78bfc Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sun, 27 Oct 2024 17:37:46 -0700 Subject: [PATCH] Repair PDF before all processing Some PDFs choke both pdfminer.six and Ghostscript but the issues can be fixed first. Fixes #1403 --- src/ocrmypdf/_pipeline.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ocrmypdf/_pipeline.py b/src/ocrmypdf/_pipeline.py index 3ab0920a..2a57ccd3 100644 --- a/src/ocrmypdf/_pipeline.py +++ b/src/ocrmypdf/_pipeline.py @@ -159,8 +159,13 @@ def triage( "Argument --image-dpi is being ignored because the " "input file is a PDF, not an image." ) - # Origin file is a pdf create a symlink with pdf extension - safe_symlink(input_file, output_file) + try: + with pikepdf.open(input_file) as pdf: + pdf.save(output_file) + except pikepdf.PdfError as e: + raise InputFileError() from e + except pikepdf.PasswordError as e: + raise EncryptedPdfError() from e return output_file except OSError as e: log.debug(f"Temporary file was at: {input_file}")