Hi,
we experience some issues similar to Add Non-English characters in PDF in C# using Aspose.PDF - System.NullReferenceException - #11 by asad.ali
Is the ttf-mscorefonts-installer really required for usage of Aspose.Pdf? The problem is that these fonts pose a license challenge for us and we dont want to use them. We bought the big Aspose package and are now required to maybe even buy/license these font for proper usage? This seems excessive. Is there a way to substitute these fonts in the context of Documents and umlauts (ü,ä,ö,…)?
We found out the following variants:
- No umlauts, no msfonts => No Problem
- With Umlauts, With msfonts => No Problem
- With Umlauts, no msfonts => NRE
- Deleting all fonts in /usr/share/fonts/truetype/msttcorefonts => NRE
- Deleting all fonts except arial => No Problem
- “renaming” e.g. the JetBrains font in Arial and overwriting in “/usr/share/fonts/truetype/msttcorefonts/” => No Problem
Where Renameing is not just set a file name, it means setting font information in the .ttf-File
Font name: “ArialMT” Family-name “Arial”, Name: “Arial” (here FontForge was used)
System specs:
Aspose.Pdf: 21.6.0
Linux (Alpine)
DotNet Core 5.0
The Liberation Mono fonts is installed and can be loaded by Aspose.
Example code:
Document document = new();
var page = AddNewPage(document);
string pureTextLine = “asdfghjkl ä”;
TextFragment textFragment = new();
// Set text properties
textFragment.TextState.Font = FontRepository.FindFont(“Liberation Mono”, FontStyles.Regular, true);
textFragment.TextState.FontSize =12;
//Add text
textFragment.Text = pureTextLine;
page.Paragraphs.Add(textFragment);
var targetStream = new MemoryStream();
document.Save(targetStream, SaveFormat.Pdf);
return targetStream;
Error:
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=Aspose.PDF StackTrace: at Aspose.Pdf.Text.Font…ctor(#=zzAdlzqBLBBM$ix0YtLsrQlI= #=zZSFEfbA=) at #=z3NJn0rgKZdfKwcCHUdmeHHRQ8$eVipejZ9FEpyF4rqRrpnUVUwQt7Ms=.#=zrx9TPK6SqTkjNDxSoJniVD5cLAlb(String #=zzrtNc8o=, Font #=zZSFEfbA=, Font& #=zW79ZnQuj9gQsPx4rIHpXbBc=) at Aspose.Pdf.Text.TextSegment.set_Text(String value) at Aspose.Pdf.Text.TextFragment.#=zt4EkmOB5ZkkA(String #=z24s_ez0=) at Aspose.Pdf.Text.TextFragment.#=zIE1AgFg=(TextFragment #=z3e1d2lk=) at Aspose.Pdf.Text.TextFragment.Clone() at Aspose.Pdf.Text.TextParagraph.#=zDBGD9u50iB6qu5c1Zfq8G34=() at Aspose.Pdf.Text.TextParagraph.#=zu3Bu$kdadD10Ff3xyvlHhu8=(Boolean #=zU2r_DXg=) at Aspose.Pdf.Text.TextParagraph.#=zu3Bu$kdadD10Ff3xyvlHhu8=() at Aspose.Pdf.Text.TextParagraph.EndEdit() at #=zJLgYjJ542J$N43G9JAlCcAI=.#=zkLcmE3lnceF_(TextFragment #=z3e1d2lk=, Rectangle #=zlvYFYAs=,