You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from PyPDF2 import PdfReader, PdfWriter
def reRead(filename):
reader = PdfReader(filename)
writer = PdfWriter()
page = reader.pages[0]
fields = reader.get_fields(). # <- this is empty when you read the output pdf from previous time.
writer.add_page(page)
writer.update_page_form_field_values(
writer.pages[0], {"Name": "hello1"}
)
with open("filled-out.pdf", "wb") as output_stream:
writer.write(output_stream)
# first time works
reRead("templates/sample_pdf.pdf")
# second time doesnt work
reRead("filled-out.pdf")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
Couple of problems:
reader.get_fileds()
do not work the second time if you try to read the file that you just written to.Used the forms code from here https://pypdf2.readthedocs.io/en/latest/user/forms.html
PDF sample https://royalegroupnyc.com/wp-content/uploads/seating_areas/sample_pdf.pd
error.in.filling.pdf.form.mov
f
Beta Was this translation helpful? Give feedback.
All reactions