Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pypdf/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
ArrayObject,
ContentStream,
DecodedStreamObject,
Destination,
DictionaryObject,
EncodedStreamObject,
IndirectObject,
Expand All @@ -75,6 +76,7 @@
PdfObject,
StreamObject,
TextStringObject,
TreeObject,
is_null_or_none,
read_object,
)
Expand Down Expand Up @@ -138,6 +140,8 @@ def __init__(
elif password is not None:
raise PdfReadError("Not an encrypted file")

self._named_destinations_cache: Optional[dict[str, Destination]] = None

def _initialize_stream(self, stream: Union[StrByteType, Path]) -> None:
if hasattr(stream, "mode") and "b" not in stream.mode:
logger_warning(
Expand Down Expand Up @@ -1274,3 +1278,18 @@ def _repr_mimebundle_(
data = {k: v for k, v in data.items() if k not in exclude}

return data

def _get_named_destinations(
self,
tree: Union[TreeObject, None] = None,
retval: Optional[dict[str, Destination]] = None,
) -> dict[str, Destination]:
"""Override from PdfDocCommon. In the reader we can assume this is
static, but not in the writer.
"""
if tree or retval:
return PdfDocCommon._get_named_destinations(self, tree, retval)

if self._named_destinations_cache is None:
self._named_destinations_cache = PdfDocCommon._get_named_destinations(self)
return self._named_destinations_cache
Loading