Is there a chance to create a font from URI? Something like:
// c# code
string fontUri = "https://www.manyfonts.com/VAGRoundedStd-Thin.ttf";
BaseFont myfont = BaseFont.CreateFont(fontUri, BaseFont.CP1252, BaseFont.EMBEDDED);
// or
Font font = FontFactory.GetFont(fontUri, BaseFont.CP1252,false, 9);
I also tried in binary
public static Font GetFont()
{
string fontUri = Config.FONT_URI;
Console.WriteLine(fontUri);
byte[] fontBinary = new WebClient().DownloadData(fontUri);
BaseFont bf = BaseFont.CreateFont(
"VAGRoundedStd-Thin.ttf",
BaseFont.WINANSI,
BaseFont.EMBEDDED,
false,
fontBinary,
null
);
return new Font(bf, 12, Font.NORMAL, Colors.PINK);
}
Now I get:
Unhandled Exception: System.NotSupportedException: No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
at System.Text.Encoding.GetEncoding(Int32 codepage)
at iTextSharp.text.pdf.TrueTypeFont.ReadStandardString(Int32 length)
at iTextSharp.text.pdf.TrueTypeFont.Process(Byte[] ttfAfm, Boolean preload)
at iTextSharp.text.pdf.TrueTypeFont..ctor(String ttFile, String enc, Boolean emb, Byte[] ttfAfm, Boolean justNames, Boolean forceRead)
My code is in a lambda function and cannot access filesystem. Maybe loading the ttf in memory and then somehow in iTextSharp? any workaround is welcome.