I just started a project for a personalized bookkeeping software where I fill in the results in a premade PDF form. I have everything working correctly but in one of the forms the text entered with iText7 has a different font then fields that are calculated atomatically or entered manually. When I click in the form field of the resulting pdf the font changes from the displayfont to the real font.
Is there a way to set the default font used by iText7 to fill in fields? This isn't a problem on the other forms so I'm not sure how to handle this. I use the SetValue(string value, string display) method to set the text because I need currency formatting.
EDIT: I have other forms that don't have this problem. I checked out the font on the fields on those forms and get this result:
{PdfFont{fontProgram=Times-Roman}}
embedded: false
fontEncoding: {iText.Kernel.Font.DocFontEncoding}
fontProgram: {Times-Roman}
forceWidthsOutput: false
newFont: false
notdefGlyphs: Count = 0
shortTag: {byte[256]}
subset: false
subsetRanges: null
toUnicode: null
The form with the issues has the following font properties on the fields:
{PdfFont{fontProgram=Helvetica}}
embedded: false
fontEncoding: {iText.IO.Font.FontEncoding}
fontProgram: {Helvetica}
forceWidthsOutput: false
newFont: true
notdefGlyphs: Count = 0
shortTag: {byte[256]}
subset: true
subsetRanges: null
toUnicode: null
The bad form uses a new font whereas the good form uses the font it is supposed to. I've tried the following (field = fieldname, value = text for the field):
PdfAcroForm form = PdfAcroForm.GetAcroForm(PdfDocument, true);
PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
PdfFormField formField = form.GetField(field.ToString());
formField.SetFont(font);
formField.SetValue(value);
Sadly this does nothing and I still end up with fields that render as Helvetica. When I click on a field it turns to Times Roman but that was always the case.
I checked both forms with RUPS and they do look different: 1 = bad pdf, 2 = good pdf
On the bad PDF the Acroform is indirect while on the good form acroform is a proper dictionary. Also the acroform on the bad pdf doesn't contain default resources containing a font dictionary. I'm not really up to speed on Dictionaries and such so if anyone can point me in the direction on how to fix this I'd be grateful.