Fix "readLinearizationData for file that is not linearized"

pikepdf 2.1.0 throws wrong type of exception in this case, so special-case it.

Closes #680
Closes #681
This commit is contained in:
James R. Barlow
2020-11-18 11:52:17 -08:00
parent 1f598da3c1
commit d71e50e83d
2 changed files with 11 additions and 6 deletions
+1 -6
View File
@@ -55,6 +55,7 @@ from ocrmypdf._validation import (
)
from ocrmypdf.exceptions import ExitCode, ExitCodeException
from ocrmypdf.helpers import (
NeverRaise,
available_cpu_count,
check_pdf,
pikepdf_enable_mmap,
@@ -301,12 +302,6 @@ def exec_concurrent(context: PdfContext):
copy_final(pdf, options.output_file, context)
class NeverRaise(Exception):
"""An exception that is never raised"""
pass # pylint: disable=unnecessary-pass
def configure_debug_logging(log_filename, prefix: str = ''):
"""
Create a debug log file at a specified location.
+10
View File
@@ -58,6 +58,10 @@ class Resolution(namedtuple('Resolution', ('x', 'y'))):
return f"Resolution({self.x}x{self.y} dpi)"
class NeverRaise(Exception):
"""An exception that is never raised"""
def safe_symlink(input_file: os.PathLike, soft_link_name: os.PathLike):
"""
Helper function: relinks soft symbolic link if necessary
@@ -191,6 +195,12 @@ def check_pdf(input_file: Path) -> bool:
pdf.check_linearization(sio)
except RuntimeError:
pass
except (
getattr(pikepdf, 'ForeignObjectError')
if pikepdf.__version__ == '2.1.0' # This version may throw wrong exception
else NeverRaise
):
pass
else:
linearize = sio.getvalue()
if linearize: