Add Non-English characters in PDF in C# using Aspose.PDF for .NET - System.NullReferenceException


We are using Aspose.Pdf for .NET version 20.3 which is getting deployed in Pivotal Cloud Foundry (PCF) cloud environment on window stack/os.

Below line is throwing exception when we try to set Non-English(Fr) content like “Date d’arrivée prévue”

new TextFragment { Text = “Date d’arrivée prévue” }

TextFragment had exception : System.NullReferenceException: Object reference not set to
an instance of an object.
at Aspose.Pdf.Text.Font…ctor(#=zaCT$kc$RUo7Q4ubUn4tXiRE= #=zs3EEYEc=)
2TMuRGTlg1WgQliBv(String #=zgDhrh1s=, Font #=zs3EEYEc=, Font&
at Aspose.Pdf.Text.TextSegment.set_Text(String value)
at Aspose.Pdf.Text.TextFragment.set_Text(String value)

Sample Code:
public MemoryStream GeneratePdfPoc()
var table = new Table();
var hdrRow = table.Rows.Add();
var hdrRowCell = new Cell();

        hdrRowCell.Paragraphs.Add(new TextFragment { Text = "Date d’arrivée prévue" });
    catch (Exception ex)
        table.ColumnWidths = "100%";
        hdrRowCell.Paragraphs.Add(new TextFragment { Text = $"TextFragment had exception : {ex.ToString()}" });


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

    var output = new MemoryStream { Position = 0 };

    return output;

Note: same code works on my Laptop with window OS, but when deployed on PCF cloud environment it is not working.

Now since it is PCF cloud environment we can’t install the fonts on the container, how to resolve this Non-English issue?

PDF ran from PCF Could environment on Window operating system image.png (203.7 KB)

PDF ran from Local Visual studio on Window operating system : From_Local_Visualstudio.pdf (31.8 KB)



I have worked with sample code shared by you and it seems that issue is with fonts. Can you please check and make sure that required fonts are available in your deployment version.

Hi Ahmad, thanks for reply.

Since we are deploying our app in PCF cloud environment we don’t have option to install/deploy the fonts in PCF cloud container.

Is there a option to include all fonts files in our .Net project folder and SetFontsSources like one we have in Aspose.Words?



I have observed your comments. Can you please visit this thread. This will help you to set fonts folder. Please share feedback with us if there is still an issue.

Below addLocalFontPath function is not there in .Net version, it is there in Java

Also went through API FontRepository | Aspose.PDF for .NET API Reference
But could not find alternative to addLocalFontPath in .Net



Please use following sample code on your end for font path.

// connect custom font directory
FolderFontSource fs = new FolderFontSource(@“path\to\my\folder”);

Thanks Ahmad, i am able to solve the Non-Eng issue by above mentioned solution.


You are welcome.