iTextSharp AcroField.SetFieldProperty issue

Stoyan Petkov picture Stoyan Petkov · Sep 2, 2015 · Viewed 7.6k times · Source

I have AcroField:

AcroFields field = stamper.AcroFields;

and i'm using these BaseFont and Font settings:

string fontName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "times.ttf");
BaseFont bf = BaseFont.CreateFont(fontName, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = new Font(bf,12);

When i set field.SetFieldProperty(fieldName,"12",12.0f,null); and try to export my pdf all the text that was written on cyrillic does not show. I tried few different ways to fix this problem but non of them help me.

I'm not pretty sure how exactly these font setting apply on AcroFields

If anyone know something about it or can direct me to somewhere, please let me know.

Answer

Shafat Khan picture Shafat Khan · Feb 6, 2019

If you are dealing with Acro field then below snippet is useful:

        var memStream = new MemoryStream();
        var stamper = new PdfStamper(reader, memStream);
        AcroFields form = stamper.AcroFields;
        foreach(string key in form.Fields.Keys)
        {
            form.SetFieldProperty(key, "textsize", (float)7, null);
            form.SetFieldProperty(key, "textfont", bfArialUniCode, null);
            form.RegenerateField(key);
        }