|
66 | 66 | ArrayObject,
|
67 | 67 | ContentStream,
|
68 | 68 | DecodedStreamObject,
|
| 69 | + Destination, |
69 | 70 | DictionaryObject,
|
70 | 71 | EncodedStreamObject,
|
71 | 72 | IndirectObject,
|
|
75 | 76 | PdfObject,
|
76 | 77 | StreamObject,
|
77 | 78 | TextStringObject,
|
| 79 | + TreeObject, |
78 | 80 | is_null_or_none,
|
79 | 81 | read_object,
|
80 | 82 | )
|
@@ -138,6 +140,9 @@ def __init__(
|
138 | 140 | elif password is not None:
|
139 | 141 | raise PdfReadError("Not an encrypted file")
|
140 | 142 |
|
| 143 | + # cache so we don't have to parse this over and over |
| 144 | + self._named_destinations: Optional[dict[str, Destination]] = None |
| 145 | + |
141 | 146 | def _initialize_stream(self, stream: Union[StrByteType, Path]) -> None:
|
142 | 147 | if hasattr(stream, "mode") and "b" not in stream.mode:
|
143 | 148 | logger_warning(
|
@@ -1274,3 +1279,18 @@ def _repr_mimebundle_(
|
1274 | 1279 | data = {k: v for k, v in data.items() if k not in exclude}
|
1275 | 1280 |
|
1276 | 1281 | return data
|
| 1282 | + |
| 1283 | + def _get_named_destinations( |
| 1284 | + self, |
| 1285 | + tree: Union[TreeObject, None] = None, |
| 1286 | + retval: Optional[dict[str, Destination]] = None, |
| 1287 | + ) -> dict[str, Destination]: |
| 1288 | + """Override from PdfDocCommon. In the reader we can assume this is |
| 1289 | + static, but not in the writer. |
| 1290 | + """ |
| 1291 | + if tree or retval: |
| 1292 | + return PdfDocCommon._get_named_destinations(self, tree, retval) |
| 1293 | + |
| 1294 | + if self._named_destinations is None: |
| 1295 | + self._named_destinations = PdfDocCommon._get_named_destinations(self) |
| 1296 | + return self._named_destinations |
0 commit comments