Commit 1833358
committed
Access pdf annotations while inside pikepdf.Pdf context manager.
Depending on the exact way the pdf file is written, iterating over
Annots can fail after the file has been closed. This is not the case
for matplotlib-generated pdfs, but is the case for mplcairo-generated
ones. As a simple repro of the different behavior between
"in-the-contextmanager" and "out-of-the-contextmanager":
```
from matplotlib import pyplot as plt
plt.figtext(.5, .5, "hello, world", url="https://www.google.com")
plt.savefig("/tmp/test.pdf", backend="pdf")
import pikepdf
with pikepdf.Pdf.open("/tmp/test.pdf") as pdf:
page = pdf.pages[0]
print(repr(page.Annots)) # within contextmanager: ok
with pikepdf.Pdf.open("/tmp/test.pdf") as pdf:
page = pdf.pages[0]
print(repr(page.Annots)) # after contextmanager: AttributeError
```1 parent 7b3ac93 commit 1833358
1 file changed
+17
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
237 | 239 | | |
238 | 240 | | |
239 | 241 | | |
| |||
251 | 253 | | |
252 | 254 | | |
253 | 255 | | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
260 | 264 | | |
261 | 265 | | |
262 | 266 | | |
| |||
0 commit comments