How can I update data obtained with getField? #766
Replies: 6 comments
-
Have a look at updatePageFormFieldValues in the PdfFileWriter class. You will need to call 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. |
Beta Was this translation helpful? Give feedback.
-
Too bad… I know this can be done: https://yoongkang.com/blog/pdf-forms-with-python/ |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Okay, this is somewhat above my level, but I will give it a chance. Thank you! |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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.
Beta Was this translation helpful? Give feedback.
All reactions