System.NullRefernceException: object reference not set to an instance of an object at Aspose.Pdf.Text.Font

using Aspose.Pdf;
using System;
using System.IO;
using System.Reflection.Metadata;
using System.Text;
using Aspose.Pdf.Text;

namespace HtmlToPdf12
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                License lic = new License();
                 lic.SetLicense("/home/ctadmindev/licenses/Aspose.Total.NET.lic");
                string str = String.Format(@"<html>
                    <body>
                    <div style='width: 595px;height: 842px;border: 1px solid #ccc;margin: 0 auto;margin-top:10px; margin-bottom:10px'><table style='font-family:Calibri,sans-serif;'><tbody><tr><td style='padding: 0;background: #D5E2C9;display:inline-block;width: 143px;height: 75px;margin-bottom: 20px;margin-right: 2px;'><div style='font-size: 12px;text-align: center;margin: 5px;width: 128px;font-weight: 600;'><div style='padding-top: 10px;'> Document ID:</div><div style='font-size: 26px;'> YQ964D4A</div></div></td><td style='padding: 0;background: #D5E2C9;display:inline-block;width: 280px;height: 75px;margin-bottom: 20px;'><div style='padding-top: 7px;padding-left: 6px;'><table style='font-size:12px;padding-top: 5px;'><tbody><tr><td width='10'><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td width='50'><b>Title</b></td><td><b>:</b></td><td>Salary Certificate</td></tr><tr><td width='10'><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Issued On</b></td><td><b>:</b></td><td>6-Mar-2020</td></tr><tr><td width='10'><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Valid Till</b></td><td><b>:</b></td><td>Valid Forever</td></tr></tbody></table></div></td><td style='padding: 0;background: #D5E2C9;display:inline-block;width: 164px;height: 75px;margin-bottom: 20px;margin-left: 2px;'><div style='font-size: 12px;/* text-align: center; */margin: 5px;width: 153px;font-weight: 600;'><div style='padding-top: 10px;text-align: center;'>Chain ID:</div><div style='font-size: 20px;text-align: center;'> CHAINtrail971</div><div style='font-size: 19px;text-align: center;'> <img src='https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Flag_of_the_United_Arab_Emirates.svg/1200px-Flag_of_the_United_Arab_Emirates.svg.png' width='20' height='12' style=' /* text-align: center; */ '></div></div></td></tr><tr><td style='padding-left: 30px;'><div style='font-size:12px;font-weight:600;color: #25388F;padding-left: 201px;padding-bottom: 5px;'> eSignature Information:</div></td></tr><tr><td style='padding-left: 20px;'><div style='font-size:12px;font-weight:600;color: #25388F;'> Credential Issuer:</div></td></tr><tr><td colspan='1' style='padding: 0px 15px;'><table><tbody><tr><td style='background:#F1F0F6;border-radius:8px;display:inline-block;width: 125px;height: 65px;'><table><tbody><tr><td> <img id='' src='https://chaintrailwebuat.blob.core.windows.net/publicimages/Etisalat_black_logo.png' style='width: 121px;text-align: center;height: 61px;'></td></tr></tbody></table></td><td style='background:#F1F0F6;border-radius:8px;width: 429px;/* display: inline-block; */'><table style='font-size:12px;padding-left:5px'><tbody><tr><td width='10'><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td width='85'><b>Institution Name</b></td><td><b>:</b></td><td>Etisalat</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>CHAINtrail ID</b></td><td><b>:</b></td><td>202000000006</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Country</b></td><td><b>:</b></td><td>United Arab Emirates</td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style='padding-left: 20px;'><div style='font-size:12px;font-weight:600;color: #25388F;'> Signatory(s):</div></td></tr><tr><td colspan='1' style='padding: 0px 15px;'><table><tbody><tr><td style='background:#F1F0F6;border-radius:8px;display:inline-block;width: 125px;height: 109px;'><table><tbody><tr><td style='height: 105px;padding-left: 10px;'> <img id='' src='imgInstitutionCredential.jpg' style='width: 100px;text-align: center;height: 80px;'></td></tr></tbody></table></td><td style='background:#F1F0F6;border-radius:8px;width: 430px;'><table style='font-size:12px;padding-left:5px'><tbody><tr><td width='10'><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td width='85'><b>eSigned By</b></td><td><b>:</b></td><td>Imran Younis</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Designation</b></td><td><b>:</b></td><td>HR Manager</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Employee ID</b></td><td><b>:</b></td><td>ET10021</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Email</b></td><td><b>:</b></td><td>iyounis@etisalat.ae</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>eSigned On</b></td><td><b>:</b></td><td>6-Mar-2020</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>CHAINtrail ID</b></td><td><b>:</b></td><td>102000000006</td></tr></tbody></table></td></tr></tbody></table></td></tr><tr></tr><tr><td style='padding-left: 20px;'><div style='font-size:12px;font-weight:600;color: #25388F;'> Issued To:</div></td></tr><tr><td colspan='1' style='padding: 0px 15px;'><table><tbody><tr><td style='background:#F1F0F6;border-radius:8px;display:inline-block;width: 125px;height: 78px;'><table><tbody><tr><td style='height: 70px;padding-left: 17px;'> <img id='' src='imgInstitutionCredential.jpg' style='width: 85px;text-align: center;height: 76px;'></td></tr></tbody></table></td><td><div style='background:#F1F0F6;border-radius:8px;width: 430px;'><table style='font-size:12px;padding-left:5px'><tbody><tr><td width='10'><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td width='85'><b>Name</b></td><td><b>:</b></td><td>Gayatri Patle</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Employee ID</b></td><td><b>:</b></td><td>ET10023</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Email</b></td><td><b>:</b></td><td>patlegayatri@etisalat.ae</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>Received On</b></td><td><b>:</b></td><td>7-Mar-2020</td></tr><tr><td><div style='width: 0;height: 0;border-top: 4px solid transparent;border-bottom: 4px solid transparent;border-left: 6px solid #25388F;'></div></td><td><b>CHAINtrail ID</b></td><td><b>:</b></td><td>102000000335</td></tr></tbody></table></div></td></tr></tbody></table></td></tr><tr><td colspan='2' style='font-size: 12px;text-align: center;color: #25388F;padding: 35px 123px 0 123px;'> In case you have received this credential as an attachment via eMail, to verify if it is the original as intended by the owner</td></tr><tr><td colspan='2'><table style='width:100%;font-size:12px'><tbody><tr><td style='text-align: center;'> <img src='img2.png' style='width: 250px;height: 25px;padding-top: 10px;'></td></tr><tr><td><table style='width: 290px;font-size:12px;margin-left: 157px;font-weight: 600;padding-bottom:20px;'><tbody><tr><td style='width: 88px;padding-left: 5px;color: #25388F;'> Click <a href='https://chaintrail.com/Verify' target='_blank' style=' color: forestgreen;'>Here</a></td><td style='text-align: center;width: 83px;color: #25388F;'> Upload this Document</td><td style='text-align: center;padding-left: 21px;color: #25388F;'> Click on Verify</td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style='width: 88px;padding-left: 5px;color: #25388F;text-align: center;font-size: 12px;padding-bottom:10px;'> <b>or Goto:&nbsp;&nbsp;</b><span style='color:#d2691e'>https://uat.etisalat.ae/en/footer/about-us/hr-block-chain.jsp</span></td></tr></tbody><tfoot><tr><td style=' padding-top: 112px; padding-right: 5px; '><div colspan='2' style='background: #F8F8FF;height: 55px;padding-bottom: 10px'><table style='margin: 0 auto;'><tbody><tr><td> <span style='font-size: 12px;color: #25388F;'>Powered by&nbsp;</span></td><td> <img src='ChainTrailBLUE.png' style='width: 130px;'></td></tr></tbody></table><div style='font-style: italic;text-align: center;'> <span style='font-size: 12px;color: #25388F;'>Interparty Trust Ecosystem using Blockchain</span></div></div></td></tr></tfoot></table></div>
                    </body>
                    </html>");                
                 // create a unique file name
                string fileName = Guid.NewGuid() + ".pdf";

                // convert HTML text to byte array
                byte[] byteArray = Encoding.UTF8.GetBytes(str);

                // passing to stream
                MemoryStream stream = new MemoryStream(byteArray);
                HtmlLoadOptions options = new HtmlLoadOptions();
                Aspose.Pdf.Text.FontRepository.Sources.Add( new FolderFontSource( "/usr/share/doc/ttf-mscorefonts-installer/" ));
                Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream, options);

                // create memory stream for the PDF file
                MemoryStream outputStream = new MemoryStream();
                pdfDocument.Save(outputStream);
                FileStream file = new FileStream("/home/ctadmindev/licenses/" + fileName, FileMode.Create, FileAccess.Write);
                outputStream.WriteTo(file);
                file.Close();
                outputStream.Close();
            }
            catch(Exception ex)
            {
                Console.Write(ex);
            }
        }
    }
}

========================================================
I am using the above code to test in linux .
when i run the dotnet run command, I get the following error.

System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Text.Font…ctor(#=zIEV6AkUK7JTf7_aGwcjjY20= #=zlWgbMEo=)

Can you please help me in understanding this?
and also please suggest the changes in the code.

@vinays

The code which you have shared seems fine. It should work and generate expected output. However, the Stack Trace is encrypted and apparently it is showing that the error cause is missing font. We need to further investigate the scenario in details. Would you kindly share the complete stack trace in text format as well as the Linux version and name details with us.

Thank You Asad.ali for replying. I am sorry for replying this late, was occupied with some other work.
Could you please check the below details? and help me in resolving this.

System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Text.Font…ctor(#=zIEV6AkUK7JTf7_aGwcjjY20= #=zlWgbMEo=)
at #=zvhGFYF4WvYmsypCRm15eZtb3Dck0aWOFsTGXeJo1VDJWF49JqBBgbFM=.#=zOjBTH3yCoviPRY38r9SGCFujYuSK(String #=zaqRXLAk=, Font #=zlWgbMEo=, Font& #=z8IkgNIIZrMLuV5G7xO1LRyY=)
at #=zzR6KSvmMFVEEMYr2S18RzkIyGWcf.#=z4GPZU9URfUQ7(String #=zpfWl3e8=)
at Aspose.Pdf.Text.TextFragment.#=zwWDeDTNx8GuD(String #=zpfWl3e8=)
at Aspose.Pdf.Text.TextFragment…ctor(String text)
at #=zq3TrW91UrtJYbw3lOI8bLN$Mc40pzUJiZg==`1.#=zzcVxh4Q=(String #=zpfWl3e8=, PointF #=zOjnWdME=)
at #=zKze2hVfY_8d8ddAetO3_U6GGpj62.#=z4zx_78g=(#=zDmqQL7lTeZzYp79Ix5c9JoJQETDwX6ClWw== #=zUdPH5zFfAgdE, Boolean #=zXeyJ5PxFwA3WyT77Lw==, #=z_iTjA2qzRln1bNtsG0$digoSBWIbMgYoFQ== #=zGngBsZ0=)
at #=zKze2hVfY_8d8ddAetO3_U6GGpj62.#=zyMSOZJpvC_aI(#=zh$15j1mRKGS7Nb_gCL5BuiR2XzVhPIJytg== #=zpuIeXxU=, Boolean #=zXeyJ5PxFwA3WyT77Lw==, #=z_iTjA2qzRln1bNtsG0$digoSBWIbMgYoFQ== #=zGngBsZ0=)
at #=zKze2hVfY_8d8ddAetO3_U6GGpj62.#=zyMSOZJpvC_aI(#=zh$15j1mRKGS7Nb_gCL5BuiR2XzVhPIJytg== #=zpuIeXxU=, Boolean #=zXeyJ5PxFwA3WyT77Lw==, #=z_iTjA2qzRln1bNtsG0$digoSBWIbMgYoFQ== #=zGngBsZ0=)
at #=zKze2hVfY_8d8ddAetO3_U6GGpj62.#=zY2hiEeRi$ilrSfFePw==(#=z12sR4JwbPICD$O2PGg== #=zA2EnNl9uMn6RByilAg==, Boolean #=zXeyJ5PxFwA3WyT77Lw==, #=z_iTjA2qzRln1bNtsG0$digoSBWIbMgYoFQ== #=zGngBsZ0=)
at #=zKze2hVfY_8d8ddAetO3_U6GGpj62.#=zzm8LUNU=(#=zWRUhCzXyojszmBoA1vGhActf_ockRThHBA== #=zYDFzDWU=, #=zGPjz8KNVYND1clOxPA== #=zA2EnNl9uMn6RByilAg==, Boolean #=zXeyJ5PxFwA3WyT77Lw==, #=z_iTjA2qzRln1bNtsG0$digoSBWIbMgYoFQ== #=zGngBsZ0=)
at #=zqeKOY0nZzwteL8d6GjOIEYO_yirq_EV8E$Cu8pM=.Render(#=z67IDmZSLJr1JIuqkNdRu3bSXYxWS #=zYHckZs0=)
at #=zL$M5uCSU4txNsLe87Io01xzN9H$C3id86g==.#=zKHMdd96k$A5w(#=zFHEgCTkszcXBL0N3893xN48= #=z7iYWM7XETaNSmlfygw==, #=zSZGgSqZ8UC4pNFIXRTAFarf_nfsH[] #=zDOwlAm_y6IxC, #=z7bvrcfh_wLzrznNJ12WnTaFRPS5O #=zeJDrXYU=, TimeSpan #=zoGVXzK4=)
at #=zKuaZ0n5_UZ626AgtMv7Os82ubkJL.Render(#=z7bvrcfh_wLzrznNJ12WnTaFRPS5O #=zeJDrXYU=, TimeSpan #=zoGVXzK4=, #=zv7lhw2MccRRkf_xCIrC9GPU=[] #=zY9CzABE=, #=zchR0EnGyTYFJeQ_3a_N5H8o=[] #=zh_dKgCs=)
at #=zKuaZ0n5_UZ626AgtMv7Os82ubkJL.Render(#=z7bvrcfh_wLzrznNJ12WnTaFRPS5O #=zeJDrXYU=, TimeSpan #=zoGVXzK4=, #=zchR0EnGyTYFJeQ_3a_N5H8o=[] #=zh_dKgCs=)
at #=zUqrDdB9zAhe3DLPDJprrb9p2OTuz.Render(#=z7bvrcfh_wLzrznNJ12WnTaFRPS5O #=zeJDrXYU=, #=zysH2GpM= #=zanrpBCo=, TimeSpan #=zoGVXzK4=)
at #=zUqrDdB9zAhe3DLPDJprrb9p2OTuz.Render(#=z7bvrcfh_wLzrznNJ12WnTaFRPS5O #=zeJDrXYU=, #=zysH2GpM= #=zanrpBCo=)
at #=z5M2Uv9Zx_eZaKearhVNfgErCMkhV.#=z0evQ6Lg=(Stream #=zuGDa2k4DZhpK, Document #=z$y3AsKbJHdsO, HtmlLoadOptions #=zw7W_PPHV5Yl1, String #=zG5yEyBZdKQQo)
at #=z5M2Uv9Zx_eZaKearhVNfgErCMkhV.#=z0evQ6Lg=(Stream #=zuGDa2k4DZhpK, Document #=z$y3AsKbJHdsO, HtmlLoadOptions #=zw7W_PPHV5Yl1)
at Aspose.Pdf.Document.#=zCP0rBx0=(Stream #=zBE3H15s=, LoadOptions #=z4Gp8a2g=)
at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)
at HtmlToPdf12.Program.Main(String[] args) in /home/ctadmindev/HtmlToPdf12/HtmlToPdf12/Program.cs:line 34 Aspose.Pdf.Text.FontRepository.Sources.Add( new FolderFontSource( “/usr/share/doc/ttf-mscorefonts-installer/” ));

Linux Details:
Operating System: Ubuntu 16.04.6 LTS
Kernel: Linux 4.4.0-148-generic
Architecture: x86-64

In case if these details are not sufficient, please let me know

@vinays

We have logged an investigation ticket as PDFNET-49241 in our issue tracking system in order to further analyze this case. However, initially it seems like your program is unable to locate the windows fonts in the specified directory. Would you kindly try to install the fonts again and use the same code with Aspose.PDF for .NET 20.12. Please also make sure that fonts are present in the given fonts directory.