문제

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.

도움이 되었습니까?

해결책

It appears, at least in my case, that using encoding of IDENTITY_H actually prevented iText from embedding the entire font. I changed encoding to CP1250 and everything worked as expected.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top