Skip to main content
All docs
V24.2

DXFontRepository.QueryNotFoundFont Event

Occurs if a document requires a font that is not available in the hosting environment.

Namespace: DevExpress.Drawing

Assembly: DevExpress.Drawing.v24.2.dll

Declaration

public static event EventHandler<NotFoundFontEventArgs> QueryNotFoundFont

Event Data

The QueryNotFoundFont event's data class is NotFoundFontEventArgs. The following properties provide information specific to this event:

Property Description
ActualFont Gets the name of the font that is available in the current hosting environment as a substitute for the missing font.
FontFileData Gets or sets the font file data to be used in place of the missing font.
RequestedFont Gets the name of the font referenced in the document, but missing in the current hosting environment.

Remarks

Identify Missing Fonts and Add Them to the Repository

Your document design and layout may rely on a font type that is not available in the application’s hosting environment. As a result, the font cannot be installed on the client machine, in a Docker image, in Azure, or in another host/container. In such cases, your document replaces unavailable fonts with default fonts, which may alter the appearance of a document from the original design.

The DXFontRepository contains a mechanism to ensure that a document uses the correct fonts regardless of the hosting environment. A document will notify the application about missing typefaces so that you can obtain the required font data. Once you obtain these fonts, add them to the DXFontRepository, thus making them available to DevExpress controls.

The DXFontRepository.QueryNotFoundFont event fires for every unavailable font type. Handle this event to do the following:

  • Identify the missing typeface and its suggested alternative (e.RequestedFont and e.ActualFont)
  • Obtain the required font file from a font hosting service (such as Google Fonts)
  • Prepare a byte array and pass it to e.FontFileData

This implementation ensures that DXFontRepository contains all required font types before document generation begins.

The following code sample contains simple code that registers the preloaded “Sankofa Display” font in case it is unavailable in the application environment:

private static void Report_QueryNotFoundFont(object sender, NotFoundFontEventArgs e) {
    if (e.RequestedFont == "Sankofa Display") {
        string font = Environment.CurrentDirectory + "\\Data\\SankofaDisplay-Regular.ttf";
        e.FontFileData = File.ReadAllBytes(font);
    }
}

Obtain Missing Fonts from a Font Hosting Service (Google Fonts)

You can use the DXFontRepository.QueryNotFoundFont event to identify missing fonts and download them from a hosting service. The following example implements a service that asynchronously downloads missing fonts from Google Fonts and adds them to DXFontRepository.

Use your personal Google API Key to run this example. For instructions on how to obtain your key, see Google Fonts Developer API.

Assign your API Key to the apiKey variable in the FontCollectorService.cs file before you launch the example.

Review license agreements associated with fonts that you use. Use and redistribution permissions may vary. The service used in this example (Google Fonts) hosts fonts that are open source and available at no cost. Review the following page for details: Google Fonts FAQ.

The report in this example contains a few fonts that may be missing in many hosting environments: Ga Maamli, Roboto, and Nerko One. The example obtains these fonts if missing and makes them available to report controls. When exported to PDF, the report uses the original fonts:

View Example

DXFontRepository - A report with missing fonts

See Also