Skip to content

Conversation

@jhuber-de
Copy link
Contributor

This PR fixes a issue (#2838) with reading of choice fields that are missing the optinal /Opt key.

Note: I added a unittest with a new example pdf file. I'm not sure if the file should be added in this repo, in the sample-files repo or if it should be downloaded on demand with get_data_from_url() from the original source.
I have not committed the original file with the issue since, while technically publicly available, I have not created that PDF file myself.

Closes py-pdf#2838
According to the PDF 2.0 specification, the `/Opt` key is not required for choice fields
@codecov
Copy link

codecov bot commented Nov 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.16%. Comparing base (310e571) to head (4710d78).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3540      +/-   ##
==========================================
- Coverage   97.16%   97.16%   -0.01%     
==========================================
  Files          57       57              
  Lines        9809     9808       -1     
  Branches     1781     1781              
==========================================
- Hits         9531     9530       -1     
  Misses        167      167              
  Partials      111      111              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefan6419846
Copy link
Collaborator

I'm not sure if the file should be added in this repo, in the sample-files repo or if it should be downloaded on demand with get_data_from_url() from the original source.

For these cases, we regularly use a local copy downloaded from a GitHub comment link as we cannot safely ship the file with pypdf directly in these cases.

Feel free to use the following link: Musterservicevertrag-HNRAGB_Okt2022-Blanko.pdf

@stefan6419846 stefan6419846 changed the title BUG: Key error '/opt' in get fields BUG: Do not fail on choice field without /Opt key Dec 1, 2025
Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@stefan6419846 stefan6419846 merged commit 0b7346a into py-pdf:main Dec 1, 2025
16 checks passed
stefan6419846 added a commit that referenced this pull request Dec 7, 2025
## What's new

### Performance Improvements (PI)
- Optimize loop for layout mode text extraction (#3543) by @FelipeErmeson

### Bug Fixes (BUG)
- Do not fail on choice field without /Opt key (#3540) by @jhuber-de

### Documentation (DOC)
- Document possible issues with merge_page and clipping (#3546) by @stefan6419846
- Add some notes about library security (#3545) by @stefan6419846

### Maintenance (MAINT)
- Use CORE_FONT_METRICS for widths where possible (#3526) by @PJBrs

[Full Changelog](6.4.0...6.4.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants