Itext How to set both UTF encoding and Font to a Paragraph

Home / Uncategorized / Itext How to set both UTF encoding and Font to a Paragraph

I want to set a font to a text that is in cyrillic.I successfully convert the text to cyrilic, but i cannot set a Font to the same text.
File fontFile = new File("arialuni.ttf");
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));;
Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
Font normalFont = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC);
BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
FontSelector fs = new FontSelector();
fs.addFont(new Font(unicode));

private static void addContent(Document document,String paragraph,FontSelector fs,Font font) throws DocumentException {
Phrase phrase = fs.process(paragraph);
Paragraph p = new Paragraph(phrase.toString(),font);


Read more

Leave a Reply

Your email address will not be published. Required fields are marked *