Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Last active July 2, 2023 12:50
Show Gist options
  • Save MartinThoma/aefa6add94a524dcb871d3c5b211d29c to your computer and use it in GitHub Desktop.
Save MartinThoma/aefa6add94a524dcb871d3c5b211d29c to your computer and use it in GitHub Desktop.
from pypdf import PdfReader, PdfWriter
import pypdf
import sys
print(f"Python {sys.version} using pypdf=={pypdf.__version__}")
reader = PdfReader("Antrag.pdf") # https://www.docdroid.net/HvUlMpM/antrag-pdf
# Get the field names
# fields = reader.get_fields()
# print(fields)
# Write field data
data = {"lname": "Özcan", "fname": "Gülcan"}
writer = PdfWriter()
writer.append(reader)
writer.update_page_form_field_values(writer.pages[0], data)
writer.update_page_form_field_values(writer.pages[1], data)
with open("Antrag_output.pdf", "wb") as output_stream:
writer.write(output_stream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment