IText does not like my special characters

I am trying to create a pdf file using iText.
The file is just fine, but I can use special characters like german ä, ö, ...
The sentence I want to write (for example)

■ ... ä ... ö ...

but the way out

â -... ä ... ö ...

(I should have blurred the sentences, but I think you see what I'm talking about ...)

Somehow this black block thing and all the Umlauts cannot be generated ...
The font used is as follows:

private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); 

Thus, there should be no problem with a font that does not have these characters ...
I use IntelliJ Idea for development, for encoding a .java file it is set to UTF-8, so there should be no problems either ...

I lost here; Does anyone know what I can do to make it work?

Thanks in advance and welcome gilaras

--------------- --------------- UPDATE

So here is the (part) code:

 @Controller public class Generator { ... Font font = new Font(Font.FontFamily.TIMES_ROMAN, 9f, Font.BOLD); ... Paragraph intro = new Paragraph("Ich interessiere mich für ...!", font_12_bold); Paragraph wantContact = new Paragraph("■ Ich hätte gerne ... ", font); ... Phrase south = new Phrase("■ Süden □ Ost-West ..."); ... @RequestMapping(value = "/generatePdf", method = RequestMethod.POST) @ResponseBody public String generatePdf(HttpServletRequest request) throws IOException, DocumentException, com.lowagie.text.DocumentException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); addMetaData(document); document.open(); addContent(document, request); document.add(new Paragraph("äöü")); document.close(); return ""; } private void addContent(Document document, HttpServletRequest request) throws DocumentException { Paragraph preface = new Paragraph(); preface.setAlignment(Element.ALIGN_JUSTIFIED); addEmptyLine(preface, 1); preface.add(new Paragraph("Rückantwort", catFont)); addEmptyLine(preface, 2); preface.add(intro); addEmptyLine(preface, 1); if (request.getParameter("dec1").equals("wantContact")) { preface.add(wantContact); } else { ... } document.add(preface); } private static void addEmptyLine(Paragraph paragraph, int number) { for (int i = 0; i < number; i++) { paragraph.add(new Paragraph(" ")); } } private static void addMetaData(Document document) { document.addTitle("..."); document.addSubject("..."); document.addKeywords("..."); document.addAuthor("..."); document.addCreator("..."); } } 

I had to endure something, but I kept some Umlaut characters and other special characters so you can see where the problem occurs ... :-)

+4
source share
1 answer

You might want to try embedding the font with this technique:

 BaseFont times = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font = new Font(times, 12, Font.BOLD); 
+2
source

Source: https://habr.com/ru/post/1394156/


All Articles