HtmlFragment not loading embedded font via styles

I am using Aspose.PDF.Drawing for .NET. See the code below:

using Aspose.Pdf;

const string LicenseFile = "Aspose.Pdf.lic";

SetAsposeLicense(LicenseFile);

byte[] pdfBytes = GeneratePdf();

File.WriteAllBytes("GeneratedReport.pdf", pdfBytes);

void SetAsposeLicense(string licensePath)
{
    License license = new();
    license.SetLicense(licensePath);
}

byte[] GeneratePdf()
{
    string html = "<style>     @import url('https://fonts.googleapis.com/css2?family=Work+Sans:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap');      #body {         font-family: 'Work Sans', sans-serif;         font-size: 1rem;         margin: 0.5%;         font-size: 11px;         color: #231F20;     }      tr.datatable-row {         vertical-align: inherit;     }      h1 {         font-size: 17px;     }      h2 {         font-size: 15px;     }      h3 {         font-size: 13px;     }      .no-wrap {         white-space: nowrap;     }      .info {         margin-top: 0px;         margin-bottom: 2px;         display: block;     }      table {         display: flex;         border-collapse: collapse;         font-size: 9px;     }      td {         text-align: left;         font-weight: normal;         padding: 3px;         border: none;     }      th {         padding: 10px;         padding-right: 5px;         text-align: left;     }      tr.datatable-row:nth-child(even) {         background: #fff;     }      tr.datatable-row:nth-child(odd) {         background: #fff;     }      .datatable-header {         display: table-header-group;         font-size: 9px;         background-color: #293F96;         color: #fff;     }      .top-left {         border-top-left-radius: 5px;     }      .top-right {         padding-right: 10px;         border-top-right-radius: 5px;     }      .datatable-row {         vertical-align: top;     }      .datatable-cell {         padding: 0.4rem;     }      .datatable-summary {         font-size: 9px;         background: #F4F5FF;         color: #231F20;     }          .datatable-summary td {             font-weight: bold;         }      .datatable-row:hover {         background-color: #e4f0ff;         color: inherit !important;     }      .hour-field-1 {         background-color: #fff;         background-clip: padding-box;         border: 1px dashed #483d3f;     }      .hour-field-2 {         background-color: #f4f5ff !important;     }      .hour-field-3 {     }      .hour-field-4 {         color: #C73800;         background-color: #f3ebe0 !important;     }      .hour-field {         border-radius: 0.25rem;         padding: 7px !important;         width: 34px;     }      .align-right {         text-align: right;     }      .avoid-break-after {         page-break-after: avoid;     }      .datatable-row td:first-child {         border-left: 1px solid #e1e8ee;     }      .datatable-row td:last-child {         border-right: 1px solid #e1e8ee;     }      .datatable-row td {         border-bottom: 1px solid #e1e8ee;     }      td {         border: 1px solid #e1e8ee;     }      tr:first-child td:first-child {         border-top-left-radius: 5px;     }      tr:first-child td:last-child {         border-top-right-radius: 5px;     }      tr:last-child td:first-child {         border-bottom-left-radius: 5px;         border-left: 1px solid #e1e8ee;     }      tr:last-child td:last-child {         border-bottom-right-radius: 5px;         border-right: 1px solid #e1e8ee;     }      tr:last-child td {         border-bottom: 1px solid #e1e8ee;     }      table {         border-collapse: separate;         border-spacing: 0;     }      td {         border: 0px;     } </style> <div id=\"body\">     <h1>Test</h1>      </div>";

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

    page.PageInfo.IsLandscape = true;
    page.PageInfo.Margin = new MarginInfo(25, 40, 25, 90);

    HtmlFragment htmlFragment = new(html)
    {
        HtmlLoadOptions = new HtmlLoadOptions
        {
            IsEmbedFonts = true,
            HtmlMediaType = HtmlMediaType.Print,
        }
    };

    page.Paragraphs.Add(htmlFragment);

    using MemoryStream pdfOutputStream = new();
    document.Save(pdfOutputStream);

    return pdfOutputStream.ToArray();
}

The given code works with Aspose.PDF.Drawing version 23.4.0 but breaks when upgrading to any higher version (up to the latest 24.5.0)

It look like the import of the font in the style element doesn’t work properly.

@victor.t

How does this manifest itself?
I tried to reproduce the question - the above code works in my environment without throwing any exceptions or freezing.

Does the output PDF look the same? Up to version 23.4.0 the output text is bold, after that it is not. Looks like the font doesn’t get applied.

version 23.4.0:
Screenshot_2.png (1001 Bytes)

version 24.5.0:
Screenshot_1.png (957 Bytes)

@victor.t
Thanks for the clarification - the problem has been reproduced.
I’ll create a task for the development team.
I understood your previous post that something happens while executing and tried to reproduce the crash when executing the code without success.

1 Like

@victor.t
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-57274

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi @sergei.shibanov ,

It’s been a while since opening this ticket. Are there any updates regarding this issue?

@victor.t

We are afraid that the earlier logged ticket hasn’t been resolved yet due to other pending issues in the queue. We will surely prioritize the ticket on a first come first serve basis and as soon as it is resolved, we will inform you via this forum thread. Please be patient and spare us some time.

We are sorry for the inconvenience.