3

I'm trying to fill out a AcroForm's textfield with iTextSharp. The Acroform textfield was created also by iTextSharp by this piece of code:

TextField Field = new TextField(OutputWriter, FieldPos, "MyField");
OutputWriter.AddAnnotation(Field.GetTextField()); // OutputWriter is writing to form.pdf

I fill 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 filled_form.pdf in Acrobat Reader, unicode characters are not visible unless I edit manually the field (e.g. I append a character by hand to the field).

I also tried to set field's font by:

BaseFont fieldFontRoman = BaseFont.CreateFont(@"C:\Windows\Fonts\times.ttf",
                                BaseFont.IDENTITY_H,
                                BaseFont.EMBEDDED);
form.SetFieldProperty("MyField", "textfont", fieldFontRoman, null);

Then, when I open filled_form.pdf in Acrobat Reader, everything looks fine unless I edit manually the field. After that, non unicode characters disappear (they change into blank spaces). They are here in the field because if I copy whole content of the field by CTRL + C and paste it to notepad, I can see all characters.

Please advise. I would like to see all characters in the field without the need of editing the field manually and of course after editing it manually I would like no characters to disappear.

Thank you

4

1 回答 1

6

创建 PdfStamper 后设置 SubstitutionFont:

stamper.AcroFields.AddSubstitutionFont(myFont.BaseFont);
于 2012-04-23T04:05:02.923 回答