I'm using pdfrw python library to fill pdf fields from a web form. Then I have to pass it to an e-signature webservice, but they want the pdf to be non editable (flatten).
I've tried to flatten it using Adobe, it works but then I can't fill it through my python code..
import pdfrw
template_pdf = pdfrw.PdfReader(input_pdf_path)
annotations = template_pdf.pages[0]['/Annots']
for annotation in annotations:
if annotation['/Subtype'] == '/Widget':
if annotation['/T']:
key = annotation['/T'][1:-1]
if key in data_dict.keys():
annotation.update(
pdfrw.PdfDict(V='{}'.format(data_dict[key]))
)
template_pdf.Root.AcroForm.update(pdfrw.PdfDict(NeedAppearances=pdfrw.PdfObject('true')))
pdfrw.PdfFileWriter().write(output_pdf_path, template_pdf)
My idea is to flatten the pdf after fill it, using pdfrw, but I really can't figure how. If anyone has encountered this problem and has a solution, it would help me a lot.