[]
In web reporting applications using ActiveReports.NET, accurate text rendering is crucial, as textual content makes up a large part of most reports. Ensuring that text is consistently and correctly rendered across different output formats, such as HTML and PDF, and in various environments, is essential for producing clear and professional reports.
This article will guide you through the key settings for configuring text rendering, including the Fonts Resolver and Line Breaks Algorithm.
If your reports require custom fonts that are not included in the system collection, or you need consistent font usage across different environments, you should implement a custom font resolver and integrate it into the ActiveReports.NET middleware.
The first step is to write code that retrieves a font resource based on parameters such as font family, style, and weight. This is achieved by implementing the IFontResolver interface, as shown in the code sample below:
using GrapeCity.Documents.Text;
using GrapeCity.ActiveReports;
internal sealed class CustomFontResolver : IFontResolver
{
public static IFontResolver Instance = new CustomFontResolver();
private readonly FontCollection _fonts;
private CustomFontResolver()
{
_fonts = new FontCollection();
// Load system fonts (e.g., Windows)
_fonts.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts));
// Load custom fonts from a specific directory
_fonts.RegisterDirectory("../Fonts");
// Set default font (Arial)
_fonts.DefaultFont = _fonts.FindFamilyName("Arial");
}
FontCollection IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic)
{
var fonts = new FontCollection();
fonts.Add(_fonts.FindFamilyName(familyName, isBold, isItalic) ?? _fonts.DefaultFont);
return fonts;
}
}Next, use the UseFontResolver method to integrate your custom font resolver into the ActiveReports.NET middleware:
using GrapeCity.ActiveReports.Aspnetcore.Viewer;
app.UseReportViewer(config =>
{
// Apply your custom implementation of IFontResolver.
config.UseFontResolver(CustomFontResolver.Instance);
});ActiveReports.NET also allows you to configure font factory settings through the Reporting Configuration. Additionally, you can specify the line break algorithm for text rendering. For more details, refer to the following articles: