Skip to content

Instantly share code, notes, and snippets.

@rxw1
Created August 23, 2023 16:26
Show Gist options
  • Save rxw1/fbb00aa4d281bf63ec7ca158f61d01f3 to your computer and use it in GitHub Desktop.
Save rxw1/fbb00aa4d281bf63ec7ca158f61d01f3 to your computer and use it in GitHub Desktop.
Bulk change PDF AcroForm text field annotation font sizes
from sys import argv
from pikepdf import Name, Pdf
def render(input: str, output: str) -> None:
with Pdf.open(input) as pdf:
for page in pdf.pages:
annots = page.get("/Annots")
if annots is not None:
for annot in [
a
for a in annots.as_list()
if a.Subtype == Name("/Widget") and hasattr(a, "FT")
]:
if annot.FT == Name("/Tx"):
annot.DA = "/Helv 10 Tf 0 g"
pdf.save(output)
if __name__ == "__main__":
render(argv[1], argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment