Open
Description
pdftk provides the feature to embed the form fields' text in the pdf itself.
This is very useful if you want to use an editable pdf as a template to be filled by code.
from the pdftk manual:
[ flatten ]
Use this option to merge an input PDF’s interactive form fields (and their data) with the PDF’s pages. Only one input PDF can be given. Sometimes used with the fill_form operation.
usage example:
with open(source, 'rb') as source_fp:
reader = PdfFileReader(source_fp)
writer.appendPagesFromReader(
reader, lambda x: writer.updatePageFormFieldValues(x, fields))
with open(dest, 'wb') as output_fp:
writer.write(output_fp, flatten_fields=True)