Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android itext using assets fonts and utf-8 text

I'm trying to create pdf files in my android application using www.itextpdf.com , but i'm confused to using font from my assets

Problem 1

1- using my .TTF font that stored in my application assets , i always used TypeFace but now itext want me a "Font variable"

the syntax is like this :

Font font = FontFactory.getFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, 18);

but it's no C:/ in android !

Problem 2

when i add a UTF-8 paragraph like Arabic or Persian , itext add nothing in PDF file

like image 360
Mojtaba Yeganeh Avatar asked Mar 08 '14 11:03

Mojtaba Yeganeh


1 Answers

I was having the exact same issue, but I found the answer in another post that can be found HERE.

Pretty much, what you are going to want to do is something similar to this:

BaseFont urName = BaseFont.createFont("assets/subFolder/fontName.TTF", "UTF-8",BaseFont.EMBEDDED);
Font urFontName = new Font(urName, 12);
like image 149
ChiuMo Studios Avatar answered Nov 12 '22 14:11

ChiuMo Studios