I’m trying to find an attribute or function that will return the page number/index of a field that I pass as an argument. E.g. get_field_page_number(field_name) -> int
I want to be able to get a page number so that I can use update_page_form_field_values()
I’ve been looking in the pypdf documentation, but I have had no luck. I think in PyPDF2 there is supposedly a field.get('/P')
function.
There is a get_destination_page_number()
but it seems like that is for something else.
I have also found get_pages_showing_field()
which looks like it’s what I’m searching for, but I don’t know how to use it. It says it is asking for a field, so I have tried this block of code:
reader = PdfReader(input_path)
writer = PdfWriter()
fields = reader.get_fields()
for field in fields:
pages = writer.get_pages_showing_field(field)
print('Field Name: ', field)
print('Pages field is in: ', pages)
This results in a ValueError: field type is invalid
error, however.
I have also tried using form_fields_dict = reader.get_form_text_fields()
and iterating through those, to the same results.
mevans_fsi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.