I created a simple PDF document using Acrobat that consists of a single test field. The font of the text field is set to David Bold. Then, I tried to fill this text field with hebrew characters using PDFBox and I get the following error:
java.lang.IllegalArgumentException: U+05D0 is not available in this font's encoding: WinAnsiEncoding
The PDFBox FAQ proposes the following solution:
Check whether the character is available in WinAnsiEncoding by looking at the PDF Specification Appendix D. If not, but if it is available in this font (in windows, have a look with charmap.exe), then load the font with PDType0Font.load(), see also in the EmbeddedFonts.java example in the source code download.
I checked the Appendix D and the characters I'm using are not part of it, as expected. However I don't really understand what the FAQ means by loading the font. I also checked the example but I don't use the same methods to fill my document. My code is as follows:
PDDocument pdfDocument = PDDocument.load(this.getClass().getClassLoader().getResourceAsStream("test.pdf"));
PDType0Font font = PDType0Font.load(pdfDocument, this.getClass().getClassLoader().getResourceAsStream("David-Bold_13087.ttf"));
PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
if (acroForm != null) {
PDTextField field = (PDTextField) acroForm.getField("test");
field.setValue("א");
}