I am trying to populate an AcroForm iTextSharp text box. The Acroform text box was also created by iTextSharp with this piece of code:
TextField Field = new TextField(OutputWriter, FieldPos, "MyField");
OutputWriter.AddAnnotation(Field.GetTextField()); // OutputWriter is writing to form.pdf
I fill out the form using this code:
PdfReader reader = new PdfReader("form.pdf");
PdfStamper filledOutForm = new PdfStamper(reader, new FileStream("filled_form.pdf", FileMode.Create));
AcroFields form = filledOutForm.AcroFields;
form.SetField("MyField", "some unicode data");
However, when I open fill_form.pdf in Acrobat Reader, Unicode characters are not displayed unless I manually edit this field (for example, I add the character manually to the field).
I also tried to set the font of the field:
BaseFont fieldFontRoman = BaseFont.CreateFont(@"C:\Windows\Fonts\times.ttf",
BaseFont.IDENTITY_H,
BaseFont.EMBEDDED);
form.SetFieldProperty("MyField", "textfont", fieldFontRoman, null);
Then, when I open the fill_form.pdf file in Acrobat Reader, everything looks great if I do not manually edit this field. After that, un unicode characters disappear (they change to spaces). They are here in the field, because if I copy the entire contents of the CTRL + C field and paste it into notepad, I will see all the characters.
. , , , , .