Your report design and layout may rely on a font type that is not available in the application's hosting environment. The font may not be installed on the client machine, in a Docker image, in an Azure Virtual Desktop, or in another host/container. In such instances, your report will substitute unavailable fonts with default options. Once a font is substituted, a report may not appear as expected/designed.
DevExpress Reports suite helps you ensure that a report uses correct fonts regardless of the hosting environment. A report notifies you about missing typefaces so you can obtain required font data. Once you obtain the fonts, add them to your report's DXFontRepository and thus make the fonts available to individual report elements/controls.
You can obtain required font data from any font hosting service. This example illustrates a service that downloads missing fonts from Google Fonts.
Note
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 without cost. Review Google Fonts FAQ to learn more.
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 make them available to report controls. When exported to PDF, the report uses the original fonts (result.pdf):
The DXFontRepository.QueryNotFoundFont event fires for every unavailable font type. The event handler does the following:
- Identifies the missing typeface and its suggested alternative (
e.RequestedFont
ande.ActualFont
) - Obtains the required font file from Google Fonts
- Prepares a byte array and passes it to
e.FontFileData
This implementation ensures that DXFontRepository
contains all required font types before document generation begins.
Important
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.
(you will be redirected to DevExpress.com to submit your response)