0

I'm adding a TextField to a pdf created with iText. Everything works as expected except when I set a custom font on the TextField. It looks normal at first, but if I ever clear the field, then stop editing, then edit again, strange characters appear when I attempt to type again.

For example, if I type in "qwerty" it actually displays "è ï E ê í ê". If I copy and paste the text, it pastes "qwerty" into any other text program. Is there an issue with encoding? Normally for creating our pdfs I only embed a subset, which are created elsewhere. I create this BaseFont embedding the entire font, but it still doesn't fix the issue.

Here is the applicable code:

final BaseFont bf = BaseFont.createFont(fontFile, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
bf.setSubset(false);
final Rectangle rect = new Rectangle(topLeft[0], topLeft[1], botRight[0], botRight[1]);
final TextField addMe = new TextField(writer, rect, fieldName);

addMe.setText("Test Me");
addMe.setFont(bf);
addMe.setFontSize(12);

addMe.setMaxCharacterLength((int) width);

writer.addAnnotation(addMe.getTextField());

All help is appreciated, thanks in advance.

4

1 回答 1

0

至少在我的情况下,使用 IDENTITY_H 编码实际上阻止了 iText 嵌入整个字体。我将编码更改为 CP1250,一切都按预期工作。

于 2013-09-04T12:32:49.523 回答