0

How do I programmatically determine the alignment and font size of a PDF form field using iTextSharp?

I am using iTextSharp to populate a PDF that contains form fields. Originally, I was populating the form fields using the standard approach:

stamper.AcroFields.SetField("field_name", "value");

But I need the ability to use different formatting in a value, such as including bold text. I am working from this Stackoverflow question/answer, which, in a nutshell, creates a simple column, populates it with a paragraph generated from HTML and then puts that resulting paragraph on top of the corresponding form field.

This is working, but there are some shortcomings. Particularly, it always left aligns the content, but the form field may be setup to center align. Likewise, it seems to use a font size that is slightly larger than what would normally fit in the form field.

This Stackoverflow question/answer shows how to get the font name used by a form field. But I'm at a loss as to how to get the font size and the alignment. It appears this information is buried within the depths of the PDF, but not accessible via properties iTextSharp (without delving into PdfDictionarys and PdfArrays and the like).

So my question is, How do I programmatically determine the alignment and font size of a PDF form field using iTextSharp?

Thanks

Community
  • 1
  • 1
Scott Mitchell
  • 8,659
  • 3
  • 55
  • 71
  • *I am working from this Stackoverflow question/answer* - as an aside: That answer shows how to add content to the page at the position of form fields but it does not fill the fields; someone programmatically reading the form values will not get your inserted values. – mkl May 27 '15 at 06:24
  • That data is stored in pdf dictionaries and array, so if you want them, you should delve into `PdfDictionaries` and `PdfArray`s. Of course: you are always welcome to write some convenience methods, but so far, there hasn't been much need for such convenience methods. – Bruno Lowagie May 27 '15 at 06:39

0 Answers0