I managed to fill in a pdf form using Python and pdfrw, I was wondering if it is possible to specify a font for the text that is being filled in, since the filled in texts doesn't match the font of the rest of the file.
I am making use of pdfrw.PdfDict()
to fill in the data to the forms.
def generate_pdf_tax_form(self):
data_dict = {
'1a': "first_name",
'1b': "last_name",
'1c': "address"
}
template_pdf = pdfrw.PdfReader('t')
annotations = template_pdf.pages[0]['/Annots']
for annotation in annotations:
if annotation['/Parent']:
key = (
annotation['/Parent']['/T'][1:-1]
+ "." + annotation['/T'][1:-1]
)
else:
key = (annotation['/T'][1:-1])
if key in data_dict.keys():
annotation.update(
pdfrw.PdfDict(V='{}'.format(data_dict[key])))
pdfrw.PdfWriter().write("/", template_pdf)