Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: '/Annots' in update_page_form_field_values #1343

Closed
javialon26 opened this issue Sep 12, 2022 · 2 comments · Fixed by #1346
Closed

KeyError: '/Annots' in update_page_form_field_values #1343

javialon26 opened this issue Sep 12, 2022 · 2 comments · Fixed by #1346
Labels
key-error Could be a bug, but also a robustness issue workflow-forms From a users perspective, forms is the affected feature/workflow

Comments

@javialon26
Copy link

javialon26 commented Sep 12, 2022

I'm filling a PDF file with the update_page_form_field_values method but if the PDF file contains at least one page without a field a KeyError was thrown.

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Linux-5.10.104-linuxkit-x86_64-with-glibc2.31

$ python -c "import PyPDF2;print(PyPDF2.__version__)"
2.10.6

Code + PDF

This is a minimal, complete example that shows the issue:

for idx, page in enumerate(reader.pages):
            writer.add_page(page)
            writer.update_page_form_field_values(
                writer.get_page(idx), self.data, FieldFlag.READ_ONLY
            )

Traceback

File "/app/.venv/lib/python3.10/site-packages/PyPDF2/_writer.py", line 625, in update_page_form_field_values
for j in range(len(page[PG.ANNOTS])):  # type: ignore
File "/app/.venv/lib/python3.10/site-packages/PyPDF2/generic/_data_structures.py", line 149, in __getitem__
return dict.__getitem__(self, key).get_object()
KeyError: '/Annots'
@pubpub-zz
Copy link
Collaborator

PR submitted

@MartinThoma MartinThoma added the workflow-forms From a users perspective, forms is the affected feature/workflow label Sep 14, 2022
@MartinThoma
Copy link
Member

@javialon26 The fix is in main and will be in PyPDF2==2.10.10 (probably on 25th of September)

@MartinThoma MartinThoma added the key-error Could be a bug, but also a robustness issue label Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
key-error Could be a bug, but also a robustness issue workflow-forms From a users perspective, forms is the affected feature/workflow
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants