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

Filled Choice Fields Not Rendered Correctly By Adobe Acrobat #2749

Closed
jacobmiller22 opened this issue Jul 11, 2024 · 6 comments
Closed

Filled Choice Fields Not Rendered Correctly By Adobe Acrobat #2749

jacobmiller22 opened this issue Jul 11, 2024 · 6 comments

Comments

@jacobmiller22
Copy link

jacobmiller22 commented Jul 11, 2024

When reading a form with Adobe Acrobat that previously had a Choice (Drop-down list in Acrobat) field populated with pypdf in the manner specified in the documentation, the default value is always rendered. Behavior does not occur with MacOS Preview.

I did see #2747 , #2611, and #2614, but I wanted to provide a full example for reproducing.

I have also tried this on version 4.3.0 and received the same behavior.

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
macOS-14.5-arm64-arm-64bit

^ Have also experienced this on AWS lambda with amd64 chip and a 2019 MBP with Intel Chip

$ python -c "import pypdf;print(pypdf._debug_versions)"
pypdf==4.2.0, crypt_provider=('local_crypt_fallback', '0.0.0'), PIL=none

Code + PDF

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

import pypdf

reader = pypdf.PdfReader("./single-dropdown-field.pdf")

writer = pypdf.PdfWriter()
pages = reader.pages[0] # Unused var, Follows the documentation
fields = reader.get_fields() # Unused var, Follows the documentation

writer.append(reader)

print("Fields before update: ", writer.get_fields())
## Formatted for readability
# Fields before update:  
# {
#     'TEST_DROPDOWN': {
#         '/T': 'TEST_DROPDOWN', 
#         '/FT': '/Ch', 
#         '/Ff': 131072, 
#         '/V': 'Unselected', # Value is currently the default value
#         '/DV': 'Unselected', 
#         '/Opt': ['Unselected', 'Item 1', 'Item 2', 'Item 3'], 
#         '/_States_': ['Unselected', 'Item 1', 'Item 2', 'Item 3']
#     }
# }
##

data = {"TEST_DROPDOWN": "Item 2"}

writer.update_page_form_field_values(
    None,
    data,
    auto_regenerate=True, # Same Behavior with both True and False
)

print("Fields after update: ", writer.get_fields())
## Formatted for readability
# Fields after update:  
# {
#     'TEST_DROPDOWN': {
#         '/T': 'TEST_DROPDOWN', 
#         '/FT': '/Ch', 
#         '/Ff': 131072, 
#         '/V': 'Item 2', # Value is correctly assigned my value
#         '/DV': 'Unselected', 
#         '/Opt': ['Unselected', 'Item 1', 'Item 2', 'Item 3'], 
#         '/_States_': ['Unselected', 'Item 1', 'Item 2', 'Item 3']
#     }
# }
##

writer.write("result-single-dropdown-field.pdf")

Share here the PDF file(s) that cause the issue. The smaller they are, the
better. Let us know if we may add them to our tests!

The below PDFs shared may be used in tests if desired. They were created for the sole purpose of creating a simple PDF to reproduce this issue.

single-dropdown-field.pdf

^ Created using Adobe Acrobat, contains a single "Drop-down list" Field with the name TEST_DROPDOWN

result-single-dropdown-field.pdf

^ Result from the script

Snapshots of form in Adobe Acrobat

Posted in comment below

Additional Details

After populating the fields, I can see the /V field is correctly set to the value I want, MacOS preview also renders the PDF correctly. Unfortunately, I need Acrobat compatibility before anything else.

@jacobmiller22
Copy link
Author

Snapshots from Adobe Acrobat

Image of PDF before populating. Default value is Unselected

Screenshot 2024-07-11 at 11 28 21 AM

Image of PDF in the Prepare a form menu

Screenshot 2024-07-11 at 11 29 00 AM

@jacobmiller22
Copy link
Author

Snapshots from Adobe Acrobat

Images of Fields properties menu:

Screenshot 2024-07-11 at 11 29 52 AM Screenshot 2024-07-11 at 11 30 02 AM

@stefan6419846
Copy link
Collaborator

Have you tried using the latest main code or the 4.3.0 version not yet available on PyPI?

@jacobmiller22
Copy link
Author

Hi @stefan6419846

I just downloaded it, I am not facing the same issue with version 4.3.0. When do you think this version will be officially released?

I appreciate everyone's efforts to build this great library!

@stefan6419846
Copy link
Collaborator

We intended to get this released already, but our release automation has not been working correctly and thus we are currently waiting for Martin as the maintainer with write permissions to tackle this manually.

@jacobmiller22
Copy link
Author

Thank you for the update!

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

No branches or pull requests

2 participants