Last active
October 11, 2022 17:11
-
-
Save 7bitlyrus/80a2a0065d123cb2c10ee3842ff6cb91 to your computer and use it in GitHub Desktop.
Unflattens/unlocks form fields for a pdf file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pdfrw # pip install pdfrw | |
import sys | |
if not len(sys.argv) != 1: | |
print(f'usage: {sys.argv[0]} filename') | |
exit() | |
filename = sys.argv[1] | |
template_pdf = pdfrw.PdfReader(filename) | |
for Page in template_pdf.pages: | |
if Page['/Annots']: | |
for annotation in Page['/Annots']: | |
annotation.update(pdfrw.PdfDict(Ff=0)) | |
if template_pdf.Root.AcroForm is not None: | |
template_pdf.Root.AcroForm.update(pdfrw.PdfDict(NeedAppearances=pdfrw.PdfObject('true'))) | |
else: | |
print("form not found") | |
exit() | |
pdfrw.PdfWriter().write('unflatten-' + filename, template_pdf) | |
print(f'Written to unflatten-{filename}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment