How to find out the correct encoding when I call BaseFont.createFont () with itext?

I have some custom Chinese font files:

aaa.ttf bbb.ttf ccc.ttf 

And I want to use them to create my PDF file using iText.

This is the code I use to create BaseFont :

 String encoding = ??? BaseFont messageBaseFont = BaseFont.createFont("fonts/aaa.ttf", encoding, BaseFont.EMBEDDED); 

But I do not know how to find encoding . Take aaa.ttf for example:

enter image description here

Is it possible to find encoding from the information? I tried some encodings like BaseFont.CP1252 or BaseFont.WINANSI , but they did not work, the output is a blank page or many characters ?????? if they are hieroglyphs.

+6
source share
1 answer

There are different answers to this question. For a complete overview, you can read Chapter 11 of my book β€œiText in Action,” but if you just want to be safe, use Identity-H for horizontal text (and Identity-V). This is actually not an encoding, but it will create a composite font in PDF format that uses Unicode: http://api.itextpdf.com/itext/com/itextpdf/text/pdf/BaseFont.html#IDENTITY_H

+8
source

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


All Articles