PDF template shows wrong font when populated by iTextSharp -
PDF template shows wrong font when populated by iTextSharp -
we have application our clients utilize adobe acrobat create pdf template completion certificate. when user completes requirements our application fills in defined fields , allows them print certificate. 1 of certificates printing in arial (helvetica) instead of requested font in (but not all) of fields.
i have checked relevent links in stack overflow , other sites none of them address failure of template display font defined in field.
code snippet:
var pdfstream = new memorystream(); var pdfreader = new pdfreader(pdftemplate); var pdfstamper = new pdfstamper(pdfreader, pdfstream); var pdfformfields = pdfstamper.acrofields; var basefont = basefont.createfont(new hostconfig().getconfigroot().getparent().fullname + "\\fonts\\arialuni.ttf", basefont.identity_h, basefont.not_embedded); pdfformfields.addsubstitutionfont(basefont); foreach (dictionaryentry de in pdfdata) { if (de.key != null && de.value != null) { var foundfield = pdfformfields.setfield(de.key.tostring(), de.value.tostring()); if (foundfield) { pdfformfields.setfieldproperty(de.key.tostring(), "setfflags", pdfformfield.ff_read_only, null); pdfformfields.setfieldproperty(de.key.tostring(), "flags", pdfannotation.flags_print, null); pdfformfields.regeneratefield(de.key.tostring()); } } } pdfstamper.formflattening = true; pdfstamper.close(); pdfstream.close(); homecoming pdfstream; using resharper debugger inspect acro fields shows have next in hashmap of field widget:
[{/da}] {/monotypecorsiva 40 tf 0 g} (font size varies in different fields)
the fields revert arial contain next in hashmap:
[{/dr}] {dictionary}
which when expanded contains:
[{/helv}] {67 0 r}
the problem persists when removing pdfformfields.addsubstitutionfont. none of fields contain glyphs or charaters other mutual latin character set.
another interesting effect if formflattening not set true, can click on fields in acrobat reader , display monotypecorsiva until move focus elsewhere.
additional information:
we looking fixing document. not free post template without permission because belongs our client.
pdf fonts itextsharp
Comments
Post a Comment