0

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.

Stoyan Petkov
  • 481
  • 8
  • 26

2 Answers2

3

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);
        }
Bob Dalgleish
  • 8,167
  • 4
  • 32
  • 42
  • by adding form.AddSubstitutionFont(bfArialUniCode); on this one works great for me. Thank you for your contribution. – MaliEbbae May 31 '19 at 04:08
1

You are using SetFieldProperty with the wrong parameters: "12" is not a field property. I assume that you want to change the font and the font size. That's done like this:

field.setFieldProperty(fieldName, "textfont", bf, null);
field.SetFieldProperty(fieldName, "textsize", 12f, null);

There's an alternatives you could use; you could define a substitution font for the complete form:

field.AddSubstitutionFont(bf);

Now bf can be used as a substitution font for all fields; you don't have to set the field property for every separate field.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • It does not work. Font size is always the same. I tried with different values for size like 6f,18f,28f, but there is no change. Also i tried and alternative way field.AddSubstitutionFont(bf) but it did not work either. I think do something wrong... – Stoyan Petkov Sep 03 '15 at 06:14
  • What if you embed the font? Are you sure the path `fontname` is correct? Are you sure the value of `fieldName` is an actual field in the PDF form? – Bruno Lowagie Sep 03 '15 at 06:55
  • Yes, i'm sure about fieldName cause i get it with foreach loop and i create their name at pdf before. Font name and its path is also correct cause it's embed in template folder at the project. But after all struggle i think i found where the problem is. I use Nitro Pro trial version. With this software i created my editable acro fields. When i check it out it has different font size and different font type. – Stoyan Petkov Sep 03 '15 at 07:24
  • So i suppose this make the difference and that you were right. iTextSharp work properly but when byte stream goes to pdf some how AcroFields apply their value size and font type just like it apply template format like \t, \n, rectangle size, margins etc.. I will try and if you want i will let you know what the result is. Thanks for your time buddy. I appreciate that. – Stoyan Petkov Sep 03 '15 at 07:24
  • 1
    @BrunoLowagie i did set field.AddSubstitutionFont(bf); but it doesnt work for some reason i need to set for every field – PyDeveloper May 14 '18 at 18:46
  • Facing same issue as @programerAnel highlighed. Any new fixes ? – Vidhya Sagar Reddy Jul 11 '19 at 14:10