How do I "flatten" a PDF-form? I have a PDF form which needs to be filled. I have a simple example where TEMP_FORM.pdf is the from and data_dict is the value to be filled in TEMP_FORM.pdf. The output file is saved as FORM1.pdf but is still editable I need flatten that file so that the value cannot be edited.
from PyPDF2 import PdfFileReader, PdfFileWriter
TEMPLATE_PATH = 'TEMP_FORM.pdf'
OUTPUT_PATH = 'FORM1.pdf'
data_dict = {
'name': 'XYZ',
'address': 'PQR',
'email': 'xyz@gmail.com',
'send_date': '2018-02-13',
'due_date': '2018-03-13'
}
if __name__ == '__main__':
input_file = PdfFileReader(open(TEMPLATE_PATH, "rb"))
output_file = PdfFileWriter()
output_file.addPage(input_file.getPage(0))
output_file.updatePageFormFieldValues(output_file.getPage(0), data_dict)
output_stream = open(OUTPUT_PATH, "wb")
output_file.write(output_stream)
output_stream.close()