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: </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 </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.