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

ROB: discard /I in choice fields for compatibility with acrobat #2614

Merged
merged 1 commit into from
May 1, 2024

Conversation

pubpub-zz
Copy link
Collaborator

@pubpub-zz pubpub-zz commented May 1, 2024

closes #2611

@stefan6419846
Copy link
Collaborator

Wouldn't it be better to set both the /I and /V fields instead?

Copy link

codecov bot commented May 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.93%. Comparing base (6d9a7ec) to head (06b7f1c).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2614      +/-   ##
==========================================
+ Coverage   94.92%   94.93%   +0.01%     
==========================================
  Files          50       50              
  Lines        8316     8318       +2     
  Branches     1667     1668       +1     
==========================================
+ Hits         7894     7897       +3     
  Misses        261      261              
+ Partials      161      160       -1     

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

@pubpub-zz
Copy link
Collaborator Author

/I should only be used for multiple choice. here Acrobat is using it on a single selection field. It does not respect the specification.
I thought about setting both but it will complexify the code to check for free text entry in a combo box, multiple entries and so one, where as the spec is clear about the fact that /V has priority.

@stefan6419846 stefan6419846 merged commit b1b55e6 into py-pdf:main May 1, 2024
17 checks passed
stefan6419846 added a commit that referenced this pull request Jun 23, 2024
## What's new

### New Features (ENH)
- Accept ETen-B5 and UniCNS-UTF16 encodings (#2721) by @pubpub-zz
- Add decode_as_image() to ContentStreams (#2615) by @pubpub-zz
- context manager for PdfReader (#2666) by @tibor-reiss
- Add capability to set font and size in fields (#2636) by @pubpub-zz
- Allow to pass input file without named argument (#2576) by @pubpub-zz

### Bug Fixes (BUG)
- Fix deprecation for Ressources when using old constants (#2705) by @stefan6419846
- Fix images issue 4 bits encoding and LUT starting with UTF16_BOM (#2675) by @pubpub-zz
- Reading large compressed images takes huge time to process (#2644) by @snanda85
- Highlighted Text Cannot Be Printed (#2604) by @Nifury
- Fix UnboundLocalError on malformed pdf (#2619) by @farjasju

### Documentation (DOC)
- Various improvements on docstrings and examples by @j-t-1

### Robustness (ROB)
- Cope with missing Standard 14 fonts in fields (#2677) by @pubpub-zz
- Improve inline image extraction (#2622) by @pubpub-zz
- Cope with loops in Fields tree (#2656) by @pubpub-zz
- Discard /I in choice fields for compatibility with Acrobat (#2614) by @pubpub-zz
- Cope with some issues in pillow (#2595) by @pubpub-zz
- Cope with some image extraction issues (#2591) by @pubpub-zz

### Maintenance (MAINT)
- Deprecate interiour_color with replacement interior_color (#2706) by @j-t-1
- Add deprecate_with_replacement to PdfWriter.find_bookmark (#2674) by @j-t-1

### Code Style (STY)
- Change Link to be a non-markup annotation (#2714) by @j-t-1

[Full Changelog](4.2.0...4.3.0)
@chrischanwz
Copy link

chrischanwz commented Jul 10, 2024

Hi, I tracked this issue from #2611 , where i was facing the same issue of not being able to fill dropdown fields (text fields are alright). i installed the latest dev ver 4.3.0, but it seems to not make a difference. can I check what changes have been made to the update_page_form_field_values method and what I am supposed to do to fill up the Dropdown fields? I greatly appreciate any help, thank you very much
currently my code looks something like this:

def handle_bom(value):
    if isinstance(value, str) and value.startswith(("\xfe\xff", "\xff\xfe")):
        value = value.encode('latin1').decode('utf-16')
    return value

# other code omitted
with open(pdf_file_base, "rb") as file:
        reader = PdfReader(file)
        writer = PdfWriter()
        writer.append(reader)  

        for i, (index, row) in enumerate(group.iterrows()):   # i am extracting data from excel sheet basically
             data_to_fill = row.to_dict()
             data_to_fill = {key: handle_bom(str(value)) for key, value in data_to_fill.items()}  # i needed to do this to solve AttributeError: 'float object has no attribute 'startswith' 
             page = writer.pages[i] 
             writer.update_page_form_field_values(page, data_to_fill, auto_regenerate=True,)

@pubpub-zz
Copy link
Collaborator Author

@chrischanwz
Can you please open a new issue to ease handling with code, pdf input and output to ease analysis

@stefan6419846
Copy link
Collaborator

For the changes: Just have a look at the diff of this PR: https://github.com/py-pdf/pypdf/pull/2614/files

For further analysis, please open a new issue as already pointed out, which includes a standalone example we can reproduce.

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.

PDF writing not filling the Dropdown
3 participants