When editing an existing PDF, occasionally the PDF contains a "free" IndirectObject that refers to nothing (correct me if I'm conceptually wrong). In this situation the reader will raise a PdfReadError:
This exception will be passed to writer._sweepIndirectReferences(). However the except statement doesn't capture this exception, but only captures ValueError, which is not a base class of PdfReadError:
except ValueError:
# Unable to resolve the Object, returning NullObject
# instead.
warnings.warn(
"Unable to resolve [{}: {}], returning NullObject "
"instead".format(data.__class__.__name__, data)
)
return NullObject()
This will crash the script.
Hence this pull request updates this line to handle the PdfReadError exception. To be safer, it's modified to capture its base class, PyPdfError:
When editing an existing PDF, occasionally the PDF contains a "free"
IndirectObject
that refers to nothing (correct me if I'm conceptually wrong). In this situation the reader will raise aPdfReadError
:This exception will be passed to
writer._sweepIndirectReferences()
. However theexcept
statement doesn't capture this exception, but only capturesValueError
, which is not a base class ofPdfReadError
:This will crash the script.
Hence this pull request updates this line to handle the PdfReadError exception. To be safer, it's modified to capture its base class,
PyPdfError
: