-1

I fill forms with field.setValue. However even though PDF document has embedded fonts in it, I am getting error "is not available in this font's encoding: WinAnsiEncoding" no matter which type of font it is. Note that this is happening for chinese or russian characters.

Kinjal P
  • 19
  • 1
  • 5
  • Do you probably try to set values containing characters outside the Latin-15 range? – mkl Aug 19 '20 at 16:33

1 Answers1

2

Your PDF documents may have embedded fonts but they apparently have been embedded with an Encoding value WinAnsiEncoding.

WinAnsiEncoding contains essentially the Latin-15 characters, so it is intended for “Western European” languages (see the Wikipedia article on this) and in particular neither for Cyrillic nor for CJK languages.

If you want to fill chinese or russian characters into form fields using PDFBox, therefore, you have to

  • either embed a font into your PDF using an appropriate encoding beforehand
  • or replace the embedded font with PDFBox right before setting the form field value, see for example this answer.
mkl
  • 90,588
  • 15
  • 125
  • 265