I create a PDF document using itextsharp and I need to connect the fonts from the Assets folder. At the moment everything works when I throw fonts in the memory of the smartphone.
System.String ttf = Android.OS.Environment.ExternalStorageDirectory +
"/arial.ttf";
var baseFont = BaseFont.CreateFont(tttt, BaseFont.IDENTITY_H,
BaseFont.NOT_EMBEDDED);
var font = new Font(baseFont, Font.DEFAULTSIZE, Font.NORMAL);
doc.Add(new Paragraph(inf1, font));
But probably no one has these fonts in the memory of the smartphone :)
I tried to get the path to the Assets folder using the following code:
public static AssetManager Assets { get; private set; }
string ttf;
using (var asset = Assets.Open("arial.ttf"))
{
var fontStream = new MemoryStream();
asset.CopyTo(fontStream);
}
or another option:
string content;
using (StreamReader sr = new StreamReader(Assets.Open("arial.ttf")))
{
content = sr.ReadToEnd();
}
but in these cases there is a problem: object reference not set to an instance of an object... on line
using (var asset = Assets.Open("arial.ttf"))
and
using (StreamReader sr = new StreamReader(Assets.Open("arial.ttf")))
Maybe there is some analog of the folder path, similar to the path to the Font in Windows ?
Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
or maybe I can somehow use the resulting TypeFace
Android.Graphics.Typeface tf = Android.Graphics.Typeface.CreateFromAsset(Application.Context.Assets, "arial.ttf");
Tell me, please, how do I set the necessary fonts in a PDF document or how to find the path to the fonts ttf, that would be inserted into the line BaseFont :)