- Home /
Use Custom font with Unity3D and ItextSharp
Because I need to use special characters, integrated itextsharp font cant handle them, I need to use my own custom font. The integration of custom font in my app is working in Editor but in Android device not.
Does any body know how to access font on android for use with itextsharp?
For my font path I'm using:
string fontPath = Application.dataPath + "/" + "FreeSans" + ".ttf";
i tried also
string fontPath = Application.persistentDataPath + "/" + "FreeSans" + ".ttf";
And for font creation I use:
BaseFont bf = BaseFont.CreateFont(fontPath , BaseFont.CP1250, true);
When I use first option it works in Unity Editor.
J.
I also tried with no luck this two options. One path goes directly to strea$$anonymous$$g assets folder located in apk file and the other one is located on android folder device, where font was copied from strea$$anonymous$$g assets folder. Every time, PDF was canceled in the middle and the process was stopped.
path = "jar:" + Application.dataPath + "!/assets/" + "FreeSans" + ".ttf";
path = System.IO.Path.Combine(Application.strea$$anonymous$$gAssetsPath, "FreeSans.ttf");
itextsharp is behaving really odd in case when you are making PDF on android.
Does any body know how to access system font from android system, to locate font on device. maybe itextsharp could manage this kind of path?
To add onto $$anonymous$$jurek's comment, I know that specifically Android (or really any mobile device) cannot see/load fonts they do not have installed on the device, so even with that solution, if you notice that it still wont show (cause im not sure if Unity would automatically install fonts) you may have to have the device install the fonts as well before it can be displayed on said device.
Thank u for your comment. That makes sense. So, do you know how I could access fonts on Android device? There must be some path i could use. Itextsharp by default cant show special characters. $$anonymous$$aybe default Android fonts can!
Answer by Kjurek · May 08, 2015 at 06:15 PM
So. After hours of scratching my head I finally got it right.
The first part of solution is written here. You have to put some DLL files to project folder. Which one, depends what encoding you have to use.
http://answers.unity3d.com/questions/42955/codepage-1252-not-supported-works-in-editor-but-no.html
The second part goes like this:
First of all you have to make path to Android system font directory with font name:
path = Path.Combine("/system/fonts/", "DroidSans.ttf");
Register that font with FontFactory:
iTextSharp.text.FontFactory.Register(path, "DroidSans");
After that you just declare font with FontFactory.GetFont:
font = iTextSharp.text.FontFactory.GetFont("DroidSans",
BaseFont.IDENTITY_H,
false,
10,
iTextSharp.text.Font.NORMAL);
And thats it!
Your answer
![](https://koobas.hobune.stream/wayback/20220613195002im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUIText can't view text with custom font correctly (android) 0 Answers
how do i change the font size on a gui text box 3 Answers
Font Size vs Screen Resolution 1 Answer
Font looks like garbage? 1 Answer