"pdfDocument.Save(dataDir);" not working on Ubuntu

This is the code I am running:

using Aspose.Pdf;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using Aspose.Pdf.Text;

namespace SignPdf
{
class SignatureSettings
{
public int LowerLeftX;
public int LowerLeftY;
public int UpperRightX;
public int UpperRightY;
public int Page;
}

class Program
{
    static void Main(string[] args)
    {
        String dataDir = @"/home/edi/DEV/files/";
        String contract = "contract.pdf";
        String sign = "sign.png";

        SignDocument(dataDir, contract, sign);
    }

    private static void SignDocument(String dataDir, String contract, String sign)
    {
        // Open document
        Document pdfDocument = new Document(dataDir + contract);

        // Get specific text information
       /* TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("test");
        pdfDocument.Pages.Accept(textFragmentAbsorber);
        TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
        TextFragment textFragment = textFragmentCollection[0];
        Console.WriteLine("Text : {0} ", textFragment.Text);
        Console.WriteLine("Position : {0} ", textFragment.Position);
        Console.WriteLine("XIndent : {0} ", textFragment.Position.XIndent);
        Console.WriteLine("YIndent : {0} ", textFragment.Position.YIndent);*/

        // Get sign coordinates
        SignatureSettings signatureSettings = GetSignatureCoordinates(6);

        // Set coordinates
        int pageNum = signatureSettings.Page;
        int lowerLeftX = signatureSettings.LowerLeftX;
        int lowerLeftY = signatureSettings.LowerLeftY;
        int upperRightX = signatureSettings.UpperRightX;
        int upperRightY = signatureSettings.UpperRightY;
        
        // Sign the pdf
        Page page = pdfDocument.Pages[pageNum];
        FileStream imageStream = new FileStream(dataDir + sign, FileMode.Open);
        page.Resources.Images.Add(imageStream);
        page.Contents.Add(new Aspose.Pdf.Operators.GSave());
        Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
        Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
        page.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(matrix));
        XImage ximage = page.Resources.Images[page.Resources.Images.Count];
        page.Contents.Add(new Aspose.Pdf.Operators.Do(ximage.Name));
        page.Contents.Add(new Aspose.Pdf.Operators.GRestore());
        dataDir = dataDir + "Final_contract.pdf";
        pdfDocument.Save(dataDir);
    }

    private static SignatureSettings GetSignatureCoordinates(int pageCount)
    {
        if (pageCount == 4)
            return new SignatureSettings() { Page = 1, LowerLeftX = 470, LowerLeftY = 150, UpperRightX = 560, UpperRightY = 200 };
        else if (pageCount == 6)
            return new SignatureSettings() { Page = 3, LowerLeftX = 530, LowerLeftY = 340, UpperRightX = 460, UpperRightY = 260 };
        else if (pageCount == 7)
            return new SignatureSettings() { Page = 3, LowerLeftX = 430, LowerLeftY = 850, UpperRightX = 510, UpperRightY = 825 };
        else if (pageCount == 9)
            return new SignatureSettings() { Page = 3, LowerLeftX = 445, LowerLeftY = 590, UpperRightX = 518, UpperRightY = 541 };
        else
            return new SignatureSettings() { Page = 3, LowerLeftX = 530, LowerLeftY = 340, UpperRightX = 460, UpperRightY = 260 };
    }

}

}

and I get
$ sudo dotnet run
libpng warning: iCCP: known incorrect sRGB profile
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at #=z3PlYrBJ2_debhLfKK_dqMyUs7YMQ.#=z6LLdLJQ=(#=zVlcpEGAL$OSr35J0MqGuW68AVe9X #=zHRtK9WqhS0SP)
at #=zEZxw4jymv1d1K6GIZowkAoM=.#=zAPSHQUM=(#=zVlcpEGAL$OSr35J0MqGuW68AVe9X #=zHRtK9WqhS0SP)
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zbDDifTTtDziLbn2xJNe0gm5rxcgPaZ$hZcjHoBU=(Object #=zO7RYX9o=)
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zTJNST24DYg9bBpTRMIwWNOlsUuZBsjhaKBKqwxE=(MethodBase #=zO7RYX9o=,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bDDifTTtDziLbn2xJNe0gm5rxcgPaZ$hZcjHoBU=(Object #=zO7RYX9o=)
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zuuqcD04R$E74EOzhbmiMFM93NpkqLszjGUp1nLUc6w24()
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zdPtM37phRagbntQo1GfSj7IUqrom(Object #=zO7RYX9o=, UInt32 #=zNRSkSVQ=)
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zVfuoGY1oj3d2gfwJxJnYukDGQojcs$j9UA==(Boolean #=zO7RYX9o=)
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zVfuoGY1oj3d2gfwJxJnYukDGQojcs$j9UA==(Boolean #=zO7RYX9o=)
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zDtyNtrenflKcABIHKkzbLYtobSPakbiQQ6goc4g=(Object[] #=zO7RYX9o=, Type[] #=zNRSkSVQ=, Type[] #=zcEKoXYg=, Object[] #=ziFY869s=)
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zQBmRGfdIJ03YjHrNjgvIsZ2CD0HGLh$3kg==(Stream #=zO7RYX9o=, String #=zNRSkSVQ=, Object[] #=zcEKoXYg=)
at #=qbsMw9cojZc3bH0BQh3iNpLdvKo_ewgpxXvDfJcFTA50=.#=zlfyNyyvOM7D7_pFjdDpZcK6zTACEq5P1RE88vnU=(Stream #=zO7RYX9o=, String #=zNRSkSVQ=, Object[] #=zcEKoXYg=)
at Aspose.Pdf.Document.#=zm4roqUQE0Aez(Stream #=zpiRk4pc=, SaveOptions #=zUR2k5Fh_vRpv)
at Aspose.Pdf.Document.#=zODPuHbIDyfuM(String #=z5eUHM1ZJWErr)
at Aspose.Pdf.Document.Save(String outputFileName)
at SignPdf.Program.SignDocument(String dataDir, String contract, String sign) in /home/edi/DEV/C# Workspace/test/Program.cs:line 67
at SignPdf.Program.Main(String[] args) in /home/edi/DEV/C# Workspace/test/Program.cs:line 27

can anybody help ?

@elmaddinmamishov

Would you please make sure that you have installed msttcorefonts package and libgdiplus package is up to dated in your system? In case issue still persists, please share your sample PDF document for our reference. We will test the scenario in our environment and address it accordingly.