diff --git a/PyPDF2/_reader.py b/PyPDF2/_reader.py index 89a5385b7..126a9313e 100644 --- a/PyPDF2/_reader.py +++ b/PyPDF2/_reader.py @@ -30,6 +30,7 @@ import os import re import struct +from types import NoneType import warnings import zlib from io import BytesIO @@ -797,12 +798,12 @@ def _build_destination( title: str, array: List[Union[NumberObject, IndirectObject, NullObject, DictionaryObject]], ) -> Destination: - page, typ = array[0:2] - array = array[2:] try: + page, typ = array[0:2] + array = array[2:] return Destination(title, page, typ, *array) # type: ignore - except PdfReadError: - warnings.warn(f"Unknown destination: {title} {array}", PdfReadWarning) + except Exception as error: + warnings.warn(f"Error when processing destination {title} {array}. {error}", PdfReadWarning) if self.strict: raise else: @@ -828,15 +829,13 @@ def _build_outline(self, node: DictionaryObject) -> Optional[Destination]: title = node["/Title"] dest = node["/Dest"] - # if destination found, then create outline - if dest: - if isinstance(dest, ArrayObject): - outline = self._build_destination(title, dest) # type: ignore - elif isinstance(dest, str) and dest in self._namedDests: - outline = self._namedDests[dest] - outline[NameObject("/Title")] = title # type: ignore - else: - raise PdfReadError(f"Unexpected destination {dest!r}") + if isinstance(dest, ArrayObject) or isinstance(dest, NoneType): + outline = self._build_destination(title, dest) # type: ignore + elif isinstance(dest, str) and dest in self._namedDests: + outline = self._namedDests[dest] + outline[NameObject("/Title")] = title # type: ignore + else: + raise PdfReadError(f"Unexpected destination {dest!r}") # if color or text format specifications present, add to outline if "/C" in node: