Aspose.pdf 23.8.0 version give null reference error while convert html to pdf using HtmlLoadOptions in .Net 6.0

private static void HtmlToPdf(string html, string pdfPath)
{
    try
    {
        string lic = Program.Configuration.GetSection("PeSetting").GetSection("AsposeLicense").Value;
        if (!string.IsNullOrEmpty(lic))
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense(lic);
        }

        Aspose.Pdf.HtmlLoadOptions options = new Aspose.Pdf.HtmlLoadOptions
        {
            // Set Print or Screen mode
            HtmlMediaType = HtmlMediaType.Print
        };

        options.PageInfo.Margin = new MarginInfo(10, 20, 10, 20);

        Document pdfDocument = new Document(html.ToStream(), options);
        pdfDocument.Save(pdfPath);
    }
    catch (Exception ex)
    {
        // Log.Error(ex, "Error in HtmlToPdf");
        throw new PeException("HtmlToPdf: " + ex.ToString(), StatusCodes.Status406NotAcceptable);
    }
}

@Jitendra_Rathore

Please try using Aspose.Pdf.Drawing (latest version) instead of Aspose.PDF in .NET 6.0 environment and see if error continues to appear. In case you are on a non-Windows environment, please try installing msttcorefonts and libgdiplus packages. If issue still persists, please share your sample HTML with us. We will test the scenario in our environment and address it accordingly.

I am using Windows environment .Could You Please provide a sample code solution or any documentation that I can refer to convert html to pdf using Aspose.Pdf.Drawing.

@Jitendra_Rathore

As shared earlier, you won’t need any special or different code snippet in order to use Aspose.Pdf.Drawing. It has all and same classes as Aspose.PDF for .NET already has and offers. For example below sample code snippet can be used with both APIs i.e. Aspose.Pdf.Drawing and Aspose.PDF:

string html = "<div><p>Aspose PDF</p><p>Test Content</p></div>";

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

Aspose.Pdf.HtmlFragment htmlFragment = new Aspose.Pdf.HtmlFragment(html);
page.Paragraphs.Add(htmlFragment);

MemoryStream docStream = new MemoryStream();
document.Save(docStream);

Therefore, you can use your original code snippet without any change. You only need to uninstall Aspose.PDF from your project and install Aspose.Pdf.Drawing instead.