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

PDF writing not filling the Dropdown #2611

Closed
visstxg opened this issue Apr 30, 2024 · 25 comments · Fixed by #2614
Closed

PDF writing not filling the Dropdown #2611

visstxg opened this issue Apr 30, 2024 · 25 comments · Fixed by #2614
Labels
workflow-forms From a users perspective, forms is the affected feature/workflow

Comments

@visstxg
Copy link

visstxg commented Apr 30, 2024

I am working on updating the editable PDF value using pypdf 4.2.0.
I am able to fill all the text fields . Having trouble filling the dropdown field.

Any specific method to do it?

@stefan6419846
Copy link
Collaborator

Please provide the details the issue template requests from you, especially the code you used and a PDF for further analysis.

@visstxg
Copy link
Author

visstxg commented Apr 30, 2024

The pdf write command I used is as follows.

from pypdf import PdfReader, PdfWriter


reader = PdfReader(input_pdf)
writer = PdfWriter()
page = reader.pages[0]
writer.append(reader)
writer.update_page_form_field_values(
    writer.pages[0],
    {
        "State": 'MN'
    }
)

the result from reader.get_fields():

'State': {'/T': 'State', '/FT': '/Ch', '/TU': 'State', '/Ff': 655360, '/V': 'AL', '/DV': ' ', '/Opt': [' ', ['AK', 'AK'], ['IL', 'IL'], ['IN', 'IN'], ['LA', 'LA'], ['MD', 'MD'], ['ME', 'ME'], ['MI', 'MI'], ['MN', 'MN'], ['NJ', 'NJ'], ['NY', 'NY'], ['VT', 'VT']], '/_States_': [' ', ['AK', 'AK'], ['IL', 'IL'], ['IN', 'IN'], ['LA', 'LA'], ['MD', 'MD'], ['ME', 'ME'], ['MI', 'MI'], ['MN', 'MN'], ['NJ', 'NJ'], ['NY', 'NY'], ['VT', 'VT']]}

Thanks

@pubpub-zz
Copy link
Collaborator

can you also share the PDF please

@visstxg
Copy link
Author

visstxg commented Apr 30, 2024

@pubpub-zz
Copy link
Collaborator

Writer is the modified document, with the fields updated. Reader is the original one : there is no link between
look in writer.get_fields() 😉

@visstxg
Copy link
Author

visstxg commented Apr 30, 2024

Writer is the modified document, with the fields updated. Reader is the original one : there is no link between look in writer.get_fields() 😉

I didn't get exactly what you meant. If you can provide little bit more explanation, it will be great. Thanks

@pubpub-zz
Copy link
Collaborator

the updated field is part of writer:
writer.get_fields()["State"]
returns:
{'/T': 'State', '/FT': '/Ch', '/TU': 'State', '/Ff': 655360, '/V': 'MN', '/DV': ' ', '/Opt': [' ', ['AK', 'AK'], ['AL', 'AL'], ['AR', 'AR'], ['AZ', 'AZ'], ['CA', 'CA'], ['CO', 'CO'], ['CT', 'CT'], ['DC', 'DC'], ['DE', 'DE'], ['FL', 'FL'], ['GA', 'GA'], ['HI', 'HI'], ['IA', 'IA'], ['ID', 'ID'], ['IL', 'IL'], ['IN', 'IN'], ['KS', 'KS'], ['KY', 'KY'], ['LA', 'LA'], ['MA', 'MA'], ['MD', 'MD'], ['ME', 'ME'], ['MI', 'MI'], ['MN', 'MN'], ['MO', 'MO'], ['MS', 'MS'], ['MT', 'MT'], ['NC', 'NC'], ['ND', 'ND'], ['NE', 'NE'], ['NH', 'NH'], ['NJ', 'NJ'], ['NM', 'NM'], ['NV', 'NV'], ['NY', 'NY'], ['OH', 'OH'], ['OK', 'OK'], ['OR', 'OR'], ['PA', 'PA'], ['RI', 'RI'], ['SC', 'SC'], ['SD', 'SD'], ['TN', 'TN'], ['TX', 'TX'], ['UT', 'UT'], ['VA', 'VA'], ['VT', 'VT'], ['WA', 'WA'], ['WI', 'WI'], ['WV', 'WV'], ['WY', 'WY']], '/States': [' ', ['AK', 'AK'], ['AL', 'AL'], ['AR', 'AR'], ['AZ', 'AZ'], ['CA', 'CA'], ['CO', 'CO'], ['CT', 'CT'], ['DC', 'DC'], ['DE', 'DE'], ['FL', 'FL'], ['GA', 'GA'], ['HI', 'HI'], ['IA', 'IA'], ['ID', 'ID'], ['IL', 'IL'], ['IN', 'IN'], ['KS', 'KS'], ['KY', 'KY'], ['LA', 'LA'], ['MA', 'MA'], ['MD', 'MD'], ['ME', 'ME'], ['MI', 'MI'], ['MN', 'MN'], ['MO', 'MO'], ['MS', 'MS'], ['MT', 'MT'], ['NC', 'NC'], ['ND', 'ND'], ['NE', 'NE'], ['NH', 'NH'], ['NJ', 'NJ'], ['NM', 'NM'], ['NV', 'NV'], ['NY', 'NY'], ['OH', 'OH'], ['OK', 'OK'], ['OR', 'OR'], ['PA', 'PA'], ['RI', 'RI'], ['SC', 'SC'], ['SD', 'SD'], ['TN', 'TN'], ['TX', 'TX'], ['UT', 'UT'], ['VA', 'VA'], ['VT', 'VT'], ['WA', 'WA'], ['WI', 'WI'], ['WV', 'WV'], ['WY', 'WY']]}

@visstxg
Copy link
Author

visstxg commented Apr 30, 2024

Yes writer.get_fields()["State"] returns with Data in '/V' but it is not showing in PDF. But I see data in Print Preview. Is there anything to do to get it showed on PDF rendering

@visstxg
Copy link
Author

visstxg commented Apr 30, 2024

Yes writer.get_fields()["State"] returns with Data in '/V' but it is not showing in PDF. But I see data in Print Preview. Is there anything to do to get it showed on PDF rendering

This issue only when open in Adobe Acrobat. Works fine in browsers

@pubpub-zz
Copy link
Collaborator

I've found the issue:
the PDF contains '/I' entries. This is the defintion from the PDF spec:
image

Acrobat is reading this entry first although:
a) the entry is not a multiple entry
b) '/I' is not in line with '/V' which should have priority.

so Acrobat is not compliant with spec.
when reading properly the spec the "/V" looks sufficient to face all cases (/V should select in fields names which is the displayed text). "/I" can be deleted without further identified impact.

@pubpub-zz
Copy link
Collaborator

local copy for test:
FRA F 6180.150.pdf

@stefan6419846
Copy link
Collaborator

At least during my tests, pdf.js would not render this correctly, while Okular does.

@visstxg
Copy link
Author

visstxg commented May 1, 2024

Thank you for working on this.

@visstxg
Copy link
Author

visstxg commented May 1, 2024

Same PDF update has some other issues as well I encountered. The same PDF has 2 pages and second page has some fields repeating but in the reader.get_fields() returns the fields only one time. But the update_page_form_field_values is not updating the field from second page

@pubpub-zz
Copy link
Collaborator

I see only one field on second page (description)
There is no field within the cells "date of accident","RailRoad Accident...", "Highway ...","First Name","Middle Initial" these seems here only if you handwrite on a printed version

@visstxg
Copy link
Author

visstxg commented May 1, 2024

Ok Got it. Thank you for the reply.

@visstxg
Copy link
Author

visstxg commented May 1, 2024

I am very new to python and PyPDF so asking. From above conversations I understand that you had a solution for the Acrobat issue with Dropdown. I see you created the PR and merged. But how can I get that changes

@stefan6419846
Copy link
Collaborator

You can either install the latest main version from GitHub or wait for us to publish the next release to allow you to install the package from PyPI (in the past, we usually did a release once a month).

@pubpub-zz
Copy link
Collaborator

To complete @stefan6419846 you can install the current dev version as shown in the documentation:
https://pypdf.readthedocs.io/en/stable/user/installation.html#development-version

@visstxg
Copy link
Author

visstxg commented May 1, 2024

Thank you for the reply

@visstxg
Copy link
Author

visstxg commented May 7, 2024

Hi, I am facing another issue in the same PDF. After updating and saving the PDF when the newly created PDF opens in that some of the field's font is too big and not showing up the whole data.

image
image

Any idea how can I solve it. Thanks

@pubpub-zz
Copy link
Collaborator

can you provide the filled document

@visstxg
Copy link
Author

visstxg commented May 8, 2024

202312532_2024-05-06.pdf

Two issues facing in this filled document is the font size in some fields and I am encrypting the writer pdf with User access permission for PRINT only. With PRINT only UAP the fields are READ ONLY, but there is a Signature field which looks like editable but not able to click or add signature in the file. Thank you

@pubpub-zz
Copy link
Collaborator

Setting PRINT only, you have unset the permission "can fill in form fields". Therefore you can not edit any fields. The signature field is not filled however Acrobat seems to set the finger cursor on it (to possibly access some verification popups???) but the field is definitely empty
font size will be addressed the other issue you've raised

@visstxg
Copy link
Author

visstxg commented May 9, 2024

Thank you for the reply. I may need to make each field read only to excluding signature to solve this right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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