You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
```
0 commit comments