|
71 | 71 | ArrayObject, |
72 | 72 | ContentStream, |
73 | 73 | DecodedStreamObject, |
| 74 | + Destination, |
74 | 75 | DictionaryObject, |
75 | 76 | EncodedStreamObject, |
76 | 77 | IndirectObject, |
|
80 | 81 | PdfObject, |
81 | 82 | StreamObject, |
82 | 83 | TextStringObject, |
| 84 | + TreeObject, |
83 | 85 | is_null_or_none, |
84 | 86 | read_object, |
85 | 87 | ) |
@@ -143,6 +145,9 @@ def __init__( |
143 | 145 | elif password is not None: |
144 | 146 | raise PdfReadError("Not an encrypted file") |
145 | 147 |
|
| 148 | + # cache so we don't have to parse this over and over |
| 149 | + self._named_destinations: Optional[Dict[str, Destination]] = None |
| 150 | + |
146 | 151 | def _initialize_stream(self, stream: Union[StrByteType, Path]) -> None: |
147 | 152 | if hasattr(stream, "mode") and "b" not in stream.mode: |
148 | 153 | logger_warning( |
@@ -1273,3 +1278,17 @@ def _repr_mimebundle_( |
1273 | 1278 | data = {k: v for k, v in data.items() if k not in exclude} |
1274 | 1279 |
|
1275 | 1280 | return data |
| 1281 | + |
| 1282 | + def _get_named_destinations( |
| 1283 | + self, |
| 1284 | + tree: Union[TreeObject, None] = None, |
| 1285 | + retval: Optional[Dict[str, Destination]] = None, |
| 1286 | + ) -> Dict[str, Destination]: |
| 1287 | + '''Override from PdfDocCommon. In the reader we can assume this is |
| 1288 | + static, but not in the writer.''' |
| 1289 | + if tree or retval: |
| 1290 | + return PdfDocCommon._get_named_destinations(self, tree, retval) |
| 1291 | + |
| 1292 | + if self._named_destinations is None: |
| 1293 | + self._named_destinations = PdfDocCommon._get_named_destinations(self) |
| 1294 | + return self._named_destinations |
0 commit comments