Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top