According to your code, I guess that you use PdfSharp.Xamarin.Forms library, now you want to use custom fonts for pdf, am I right?
if yes, please take a look the following code, implementing IFontResolver.
internal class FontProvider : IFontResolver
{
#region Properties
public string DefaultFontName
{
get { return "OpenSans"; }
}
#endregion
#region Fields
public ICustomFontProvider _fontProvider;
public static readonly string[] DefaultFontFiles = new string[]
{
"OpenSans-Regular.ttf",
"OpenSans-Bold.ttf",
"OpenSans-Italic.ttf",
"OpenSans-BoldItalic.ttf",
};
#endregion
#region Ctor
public FontProvider(ICustomFontProvider fontProvider)
{
_fontProvider = fontProvider;
}
#endregion
#region IFontResolver implementation
public byte[] GetFont(string faceName)
{
if (DefaultFontFiles.Contains(faceName) || _fontProvider == null)
{
var assembly = typeof(FontProvider).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream($"PdfSharp.Xamarin.Forms.DefaultFonts.{faceName}");
using (var reader = new StreamReader(stream))
{
var bytes = default(byte[]);
using (var memstream = new MemoryStream())
{
reader.BaseStream.CopyTo(memstream);
bytes = memstream.ToArray();
}
return bytes;
}
}
else
{
return _fontProvider.GetFont(faceName);
}
}
public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic)
{
string fontName;
if (familyName == DefaultFontName || _fontProvider == null)
fontName = DefaultFontFiles[Convert.ToInt32(isBold) + 2 * Convert.ToInt32(isItalic)];
else
fontName = _fontProvider.ProvideFont(familyName, isBold, isItalic);
return new FontResolverInfo(fontName);
}
#endregion
}
You can also write my own implementation of IFontResolver and assigning it to GlobalFontSettings.FontResolver.
Please take a look the following thread:
Loading a Font with PdfSharp .Net Standard preview from Xamarin.Forms fails: No appropriate font found