I have a problem using itext 5.
I connected a font file to display Cyrillic:

String absolutePath = context.getRealPath("") + "WEB-INF\\arial.ttf"; Font headerFont = FontFactory.getFont(absolutePath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 14); 

If I pass a text string to the method right in the code, then everything is fine, the text is displayed normally:

 Paragraph p1 = new Paragraph("Заявление", headerFont); 

But I use the properties settings file and if I transfer the variable from the properties file to the Paragraph then I already have the cracks displayed, by default the properties file is encoded with win1251, as I understood that PDF also displays the same encoding for Cyrillic display, but why I don’t works?

 Paragraph p1 = new Paragraph(bundle.getString("pdf.main.header"), headerFont); 

When I get a string from the properties file using getString (), then the string is returned to me in UTF-16 format

    2 answers 2

    properties files in Java are read by default in ISO 8859-1 encoding (see java.util.Properties ). You need to take some measures to convert the contents of the properties when reading, and it is better to save the files in the appropriate encoding (see native2ascii ). Alternatively, try properties in XML format.

      If you need someone, then I solved this problem as follows:
      new String(bundle.getString("pdf.signature.text").getBytes("ISO-8859-1"), "CP1251")
      I recode a string from ISO-8859-1 to CP1251 , as advised by @Igor Kudryashov