- Home /
Create iTextSharp PDF in Android
I am making a report in Unity3D with iTextSharp. When I start app from Unity it creates PDF and works perfect. But when I build App on Android device, I have a problem with creating font. Here is what I do:
BaseFont bf = BaseFont.CreateFont(System.IO.Path.Combine(Application.streamingAssetsPath, "ADOBEARABIC-BOLD_0.OTF"), BaseFont.IDENTITY_H, false);
As I have seen, the first parameter for font creation is the path to the font. My font is in
/Assets/StreamingAssets/
folder.
When I try to load it with WWW class, it can find it, but when I give just the path to the creator it won't work.
Any idea what should I do? Or is there any other way to create a font that supports Arabic characters?
EDIT:
Ok, I have somehow managed to get to the font. First I copy font from Assets to the root of the APP:
IEnumerator CopyFiles()
{
string fromPath = Application.streamingAssetsPath + "/";
string toPath = Application.persistentDataPath + "/";
string filesNamesToCopy = "ADOBEARABIC-BOLD_0.OTF";
WWW www1 = new WWW(fromPath + filesNamesToCopy);
yield return www1;
File.WriteAllBytes(toPath + filesNamesToCopy , www1.bytes);
}
And then I make BaseFont:
BaseFont bf = BaseFont.CreateFont(System.IO.Path.Combine(Application.persistentDataPath, "ADOBEARABIC-BOLD_0.OTF"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Now I get new error when try to build on Android device:
ArgumentException: Encoding name 'windows-1252' not supported Parameter: name
Hi, oxa89. Did you found the solution for your problem? I have the same problem with accessing font on android. I cant figure it out how to use a custom font with itextsharp on android. The path in Editor works with no problem. But when I export it for Android, it cant be used.
J.
Its strange issue. I really don't know why android cant handle custom font file. The path is O$$anonymous$$. Its just how android is handling fonts. What about giving a try with different ttf? On this site they are exposing that some ttf fonts are not suitable to work on android. I will try with some other ttf if this will give me some positive feed back.
I opened another ticket regarding the problem and user Dibbie commented that Android cant handle fonts that are not installed on the system. That makes sense in your example and $$anonymous$$e. So there must be some workaround where system font would be used. $$anonymous$$aybe with FontFactory register method, where you look for system fonts installed on the system and you pick one from the list. I will try that.. But there is another concern, what if unity3d cant handle system fonts? :/
Answer by Kjurek · May 08, 2015 at 06:15 PM
Here is solution to my problem:
http://answers.unity3d.com/answers/962657/view.html
Did you tried to copy DLL to project folder as it is written in this post?
http://answers.unity3d.com/questions/42955/codepage-1252-not-supported-works-in-editor-but-no.html
Because I don't need custom font, only font that can post special characters, I load it from system font directory directly on android device. Maybe, you will get a font that suits to your need in that directory also. After that I register it with FontFactory and it works!
Hope you will get some help from my solution.
Your answer
Follow this Question
Related Questions
iOS can't open local file with Application.OpenURL() 1 Answer
Opening a PDF on Android 1 Answer
How to generate pdf for android? 2 Answers
Add a pdf file 0 Answers
Argument out of Range Exception Error - Parameter Name: Index 1 Answer