We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

NullReferenceException when adding a Cell with special characters to a Table in a Document


For my PDF document generation I am using a font that is an embedded resource in my app

//_fileProvider is a reference to a EmbeddedFileProvider

using var fontStream = _fileProvider.GetFileInfo(“Fonts\arial.ttf”).CreateReadStream();
var font = Aspose.Pdf.Text.FontRepository.OpenFont(fontStream, FontTypes.TTF);
font.IsEmbedded = true;

Then I create a Document with a Page like this:

var document = new Aspose.Pdf.Document();
var page = document.Pages.Add();

Then I create a Table like this:

var table = Aspose.Pdf.Table();

var row = table.Rows.Add();
row.DefaultCellPadding = new MarginInfo
Top = 0f,
Left = 0f,
Right = 0f,
Bottom = 2f
row.DefaultCellTextState.FontSize = 8f;
row.DefaultCellTextState.Font = font;
row.DefaultCellTextState.FontStyle = FontStyles.Regular;
row.DefaultCellTextState.LineSpacing = 2f;

When I run this code in IIS on Windows the code works fine.

When I run this code in NGINX on Linux the last line generates a NullReferenceException with the following stack.

System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Text.Font…ctor(#=z2brvLsOKU772tRJv5nQEY_o= #=zL7p1K7g=)
at #=z0LKTtCfNFYTWtiha0GmMxsPWHSGDoLQUBL311LNbSF8hcdobGnd_13o=.#=zoY8bJDEpkTHw7OIy7BwM6BmTkzWD(String #=zvcoqJJY=, Font #=zL7p1K7g=, Font& #=zfygFRaU61fCpXsYGsKi8giY=)
at #=zuZzeULMWwmzG_nVT$0Q$jFjIl3Im.#=zVCtQ7t_Me_9B(String #=zGYILGEQ=)
at Aspose.Pdf.Text.TextFragment.#=zkF46K6LQJs03(String #=zGYILGEQ=)
at Aspose.Pdf.Text.TextFragment…ctor(String text)
at Aspose.Pdf.Cells.Add(String text)

When I change the line to row.Cells.Add(“VrtiC”) the code works fine on both Linux and Windows.

I think the problem is the rendering of the a special character ‘Č’ on Linux?

Is this a known problem and can you please propose a solution?


The issue seems related to missing Windows Fonts. Please try to install the msttcorefonts package along with libgdiplus package. You can also try to copy/paste all Windows fonts in “/usr/share/fonts/truetype/msttcorefonts” directory. In case you still face any issue, please feel free to let us know.


Thank you for your response.

In my initial message I specified that I am using a font that is embedded in my app:

using var fontStream = _fileProvider.GetFileInfo(“Fonts\arial.ttf”).CreateReadStream();
var font = Aspose.Pdf.Text.FontRepository.OpenFont(fontStream, FontTypes.TTF);
font.IsEmbedded = true;

This file I am referencing (arial.ttf) is embedded in my app, it is part of my app DLL.

I did this to make my app self-contained - meaning it doesn’t rely on external resources like fonts installed in the OS.

I don’t see how installing the Windows Fonts on my Linux will help since I am using the font I embedded in my app.

Could you please try to explain this, maybe I am missing something?


At the time of Document loading or initialization, the API loads all system fonts and necessary resources in the memory. Missing Windows Fonts usually causes such exceptions while using the API in Non-Windows Environments. The fonts should be present in “/usr/share/fonts/truetype/msttcorefonts” directory as Aspose.PDF for .NET scans this folder on Linux like operating systems.

Furthermore, an investigation ticket as PDFNET-50879 has been logged in our issue tracking system to analyze this particular case. We will look into its details and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.