Hi, I got the below Null reference exception when adding special non-English characters such as ä to PDF. Because my application ran in RedHat machine, I loaded mscorefonts to the app. I use aspose.pdf in .NET code.
Code to load custom fonts before creating PDF document:
private static void AddCustomFonts()
{
//get ttf resources’ names
var fontNames = typeof(IncludedExcludedDocuments).Assembly.GetManifestResourceNames().Where(name => name.EndsWith(“ttf”));
Stream fontStream;
FontSource fontSource;
FontRepository.Sources.Clear();
var count = 0;
foreach (var fontName in fontNames)
{
count++;
//get stream object of resources
fontStream = typeof(IncludedExcludedDocuments).Assembly.GetManifestResourceStream(fontName);
//create font source off the stream and add it to fontrepository
using (var ms = new MemoryStream())
{
fontStream.CopyTo(ms);
fontSource = new MemoryFontSource(ms.ToArray());
FontRepository.Sources.Add(fontSource);
}
}
}
Exception stack trace:
System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Text.Font…ctor(#=z6I97n3Q5gfsJZVKXg0iiWmI= #=z3FKqCpY=)
at #=z7bI4GhXHbP5a$tKtZ8fm06BHoRC_OkCVFa6LJsOBCZxTOHyiI6BH0LE=.#=zSC3Wf7UWH3o9b8YzOu_EPNlXTTNI(String #=zBPdu0d8=, Font #=z3FKqCpY=, Font& #=zGOQ$bzu9227AxXZqyIlAUP4=)
at #=zqWBeXkAaLyA5AHcpSX2_Dkf5a5Yj.#=zn2QRuNL7kXPN(String #=zk8kaDOI=)
at Aspose.Pdf.Text.TextFragment.#=z3AZMS32VU1kV(String #=zk8kaDOI=)
at Aspose.Pdf.Text.TextFragment…ctor(String text)
at Aspose.Pdf.Cells.Add(String text)
Do you have suggestion what I can do to prevent the exception for non-special english characters?