Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How can I update data obtained with getField? #509

Closed
MrVocabulary opened this issue Aug 5, 2019 · 6 comments
Closed

How can I update data obtained with getField? #509

MrVocabulary opened this issue Aug 5, 2019 · 6 comments
Labels
is-question Rather a question than an issue. Should usually be a Discussion instead

Comments

@MrVocabulary
Copy link

Hi! I am quite new to PyPDF2 and I am mostly using snippets of code I have found on the net. What I do is simply filling PDF forms created with Adobe Acrobat XI Pro. While it works perfectly with text fields, I am having trouble setting values of dropdown lists.

I was able to determine that what PyPDF2 sees is (with getField):

{'/FT': '/Ch', '/T': DocumentType', '/Ff': 4325378, '/V': 'D', '/DV': 'W'}

In case of getTextFields, what it shows is:

{'/FT': '/Tx', '/T': 'SupervisorName', '/Ff': 29360130}

But I haven't found a similar method for updating values of those. How can I directly manipulate/update the value of /V here? Can I just replace this entire element with another one, where /V is i.e. "P" (which is one of the choices in the PDF)?

I seek counsel.

@Joshua-IRT
Copy link

Joshua-IRT commented Aug 6, 2019

Have a look at updatePageFormFieldValues in the PdfFileWriter class.

You will need to call cloneDocumentFromReader to copy the document from the reader to the writer, then you can use updatePageFormFieldValues to update the form values.

Edit: sorry, I just saw that you want to update the value of dropdowns as well. I haven't worked out a method for doing this yet.

@MrVocabulary
Copy link
Author

Too bad… I know this can be done: https://yoongkang.com/blog/pdf-forms-with-python/
Anyways, I had hoped there is a way to just send the entire thing between { and }, but apparently I have to stick to regular text fields…

@Joshua-IRT
Copy link

You could try extending the class. I did this (snippet here - #232 (comment) ) in order to make form fields read-only. I think it would be a similar process, except that you would set a different attribute.

@MrVocabulary
Copy link
Author

Okay, this is somewhat above my level, but I will give it a chance. Thank you!

@Joshua-IRT
Copy link

You're welcome. I hope you are able to get it to work. That code snippet was my first attempt at extending the PdfFileWriter class, so I only went as far as required to get it to do what I wanted (modifying the "/Ff" attribute). But I suspect if you have a play around with modifying the attributes required for the dropdown (it might help to open your PDF form in a text editor like Notepad++ to see how the values are being written by Adobe), you can get it to work.

Note that you'll need to use the extended class (PDFModifier in my code snippet) rather than the original PdfFileWriter class to access the extra methods.

@MrVocabulary
Copy link
Author

MrVocabulary commented Aug 8, 2019

I have tried playing with the code just a bit, but there's too many things beyond my skill level at this moment. I will probably just remake the PDF-s to have only text boxes and hope somebody fixes that in PyPDF2 at some point.
Thak you nevertheless :)

@py-pdf py-pdf locked and limited conversation to collaborators Apr 16, 2022
@MartinThoma MartinThoma converted this issue into discussion #766 Apr 16, 2022
@MartinThoma MartinThoma added the is-question Rather a question than an issue. Should usually be a Discussion instead label Mar 25, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
is-question Rather a question than an issue. Should usually be a Discussion instead
Projects
None yet
Development

No branches or pull requests

3 participants