-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
BUG: Make reader.get_fields also return dropdowns with options #1114
Conversation
I think I need to check where / how we use that dictionary to understand why you've added it. Could you point me to the place in code where adding the constant improves PyPDF2? |
Co-authored-by: Martin Thoma <[email protected]>
https://pypdf2.readthedocs.io/en/latest/_modules/PyPDF2/_reader.html#PdfReader.get_fields
By adding Another solution could be adding like an overloaded function to get_fields that takes an additional list of attributes, Then it wouldn't need to update the constant attributes list. If one would want to see the items in a drop down/combo box you would need something like this: for annot in reader.pages[0]["/Annots"]:
obj = annot.get_object()
if "/T" in obj.keys():
if obj["/T"] == objectTitle:
if "/Opt" in obj.keys():
print(obj["/Opt"]) |
Thank you for explaining it 🤗 Would you mind doing the following?
I think that should do the trick while maintaining that |
I like that as a solution. I'll get that implemented. |
Codecov Report
@@ Coverage Diff @@
## main #1114 +/- ##
==========================================
+ Coverage 91.94% 91.96% +0.02%
==========================================
Files 24 24
Lines 4681 4694 +13
Branches 967 968 +1
==========================================
+ Hits 4304 4317 +13
Misses 231 231
Partials 146 146
Continue to review full report at Codecov.
|
It didn't turn out to be as simple as we had hoped. Rewriting get_fields also required a similar change in _write_field and the field object it self. There might be some refactoring that we could do as get_fields loops through the same attributes as _write_field. _write_field is only called in _build_field. _build_field is only called by get_fields. Also an issue with fields as a definition. Increasing the scope of what attributes define a field ended being the final trick. Fields objects define themselves off of the FieldDictionaryAttributes constants. |
Hey, just a short heads up: it's currently super hot in Germany. I have about 35°C in my apartment during the day and not below 28°C at night. This makes me pretty unconcentrated, meaning I can't look at as many things as I wished. TL;DR : the review might take a few days. |
its all good, stay safe man! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution 🤗
Very nice work @KourFrost ! I will make a release of PyPDF2 to PyPI today that contains your contribution! If you want, I can also add you to the https://pypdf2.readthedocs.io/en/latest/meta/CONTRIBUTORS.html list - Just send me the line I should add for you :-) |
New Features (ENH): - Add `outline_count` property (#1129) Bug Fixes (BUG): - Make reader.get_fields also return dropdowns with options (#1114) - Add deprecated EncodedStreamObject functions back until PyPDF2==3.0.0 (#1139) Robustness (ROB): - Cope with missing /W entry (#1136) - Cope with invalid parent xref (#1133) Documentation (DOC): - Contributors file (#1132) - Fix type in signature of PdfWriter.add_uri (#1131) Developer Experience (DEV): - Add .git-blame-ignore-revs (#1141) Code Style (STY): - Fixing typos (#1137) - Re-use code via get_outlines_property in tests (#1130) Full Changelog: 2.6.0...2.7.0
Thank you! This is my first real contribution to an open source project, so I'm happy to help. sure add me to the contributors list. just "KourFrost" linked to my github |
Adding
/Opt
to the attributes list get_fields() will now add /Opt if it has it. For Combo Box /Ch it will list all of the available options in the drop down menu.Closes #391