Aspose.Pdf.FontNotFoundException: Font Mangal was not found

Hi team , I am converting the html content into the pdf using the aspose.pdf . With doing that, i am facing the exception related to the Mangal font not found. I have tried adding the mangal font manually but it is not getting solved . Please find the below code reference.

HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions(basePath);

htmlLoadOptions.PageInfo.Margin = new Aspose.Pdf.MarginInfo { Left = 30, Right = 20, Top = 30, Bottom = 30 };

using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(htmlContent)))
{
// Load HTML string

String fontFolderPath = @"C:\Windows\Fonts\Mangal";
FileFontSource fs = new FileFontSource(fontFolderPath);
FontRepository.Sources.Add(fs);

documentContent = new Document(ms, htmlLoadOptions);
documentContent.Flatten();

}
environment : windows

Screenshot 2025-05-15 170429.png (62.0 KB)

@keyurkalariya

The FontNotFoundException you are encountering indicates that the Mangal font is not being recognized by the Aspose library during the conversion of HTML content to PDF. To resolve this issue, you need to ensure that the Aspose library is correctly configured to locate the Mangal font.

Here are the steps you can follow to set the font folder properly:

  1. Set the Font Folder: Instead of directly adding the font file, you should specify the folder where the font is located. Use the SetFontsLookupFolder method to point to the directory containing the Mangal font.

  2. Example Code: Here’s how you can modify your existing code to set the font folder correctly:

    HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions(basePath);
    htmlLoadOptions.PageInfo.Margin = new Aspose.Pdf.MarginInfo { Left = 30, Right = 20, Top = 30, Bottom = 30 };
    
    // Set the font folder
    FontsSettings.SetFontsLookupFolder(@"C:\Windows\Fonts");
    
    using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(htmlContent)))
    {
        // Load HTML string
        Document documentContent = new Document(ms, htmlLoadOptions);
        documentContent.Flatten();
    }
    
  3. Ensure Font Availability: Make sure that the Mangal font is indeed present in the specified folder. You can check this by navigating to C:\Windows\Fonts and confirming that the font file is there.

By following these steps, you should be able to resolve the FontNotFoundException and successfully convert your HTML content to PDF using the Mangal font.

If you continue to experience issues, please double-check the path and ensure that the font is correctly installed on your system.

Sources:
[1]: How to Set Font Folder Using C# - Aspose Documentation

I am able to generate the pdf but the mangal font is not visible in the downloaded pdf instead it showing the blank boxes instead. Help me to find the text and attach to the aspose.pdf to render the Hindi (Mangal.TTF) text. I am using the aspose version 19.12.0.

@keyurkalariya

Can you please try using 25.4/25.5 version of the API? In case issue still persists, please share your sample source HTML with us. We will test the scenario in our environment and address it accordingly.