Arabic to itext

I am trying to print arabic text inside a cell inside a table (in pdf) using Itext with the following code

Font f = FontFactory.getFont("C:\\Windows\\Fonts\\arabtype.ttf");
t.addCell(new Cell(new Phrase(name,f)));

Where the name is Arabic text But it prints "????" instead of arabic text

+3
source share
2 answers

The default encoding for FontFactory.getFont()(and almost everywhere in iText) is stored in the search (search). PUBLIC LINE! It makes life easier ... FontFactoryImp.defaultEncoding. If I remember correctly, this is initialized BaseFont.WINANSI(code page (cp) 1252).

I recommend setting it to BaseFont.IDENTITY_H:

myFontFactory.getFontImp().defaultEncoding = BaseFont.IDENTITY_H

"Identity H" , . , "Identity H".

+5

com.itextpdf.text.pdf.languages.ArabicLigaturizer itextpdf 5.4.2 :

LanguageProcessor al = new ArabicLigaturizer();
preface.add(new Paragraph(al.process("گزارش"), font));
+6

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


All Articles