Wednesday, November 30, 2011

iTextSharp AcroField Font Size

While working with iTextSharp to fill AcroFields in a PDF, I noticed the font size of the text fields were a little larger than I wanted.

I found this great post that helped me out http://www.keithnordstrom.com/?tag=/itextsharp

which boils down to this:

AcroFields fields = stamper.AcroFields;
bool set = fields.SetFieldProperty(fieldName, "textsize", 12.0f, null);

The only thing to note is that you must set the form field size before putting text into the field otherwise it won't work...

11 comments:

  1. You are awesome!! After so much searching finally got it to do the simplest thing. Thank you! =D

    ReplyDelete
  2. This just doesn't seem to work for me no matter what I do. Just returns false. I posted about it on Stack Overflow. http://stackoverflow.com/questions/15960132/itextsharp-setfieldproperty-returns-false

    Maybe you can help me?

    ReplyDelete
  3. when i copied your code snippet and used it, it worked. you may have to send me your files. something else is wrong.

    leave your email and i will send you a message. i won't publish your email address.

    ReplyDelete
  4. I was setting the field properties after setting the text. Makes sense to do it before, but it was not occurring to me and I was getting super frustrated. You probably saved me from having to buy a new monitor. Thank you!

    ReplyDelete