You can run reports on different platforms, and it is important to ensure that a report uses the same fonts. With the ActiveReports' custom font resolver, you can configure fonts for Page, RDLX, and Section reports (in the CrossPlatform compatibility mode) on different platforms.
To learn about how to configure custom fonts in the ActiveReports.config file, see Configure ActiveReports using Config File.
In some situations, you can use the custom fonts resolver through code by specifying the PageReport.FontResolver property in the Windows Forms Viewer and UseFontResolver in the JavaScript Viewer, as shown in the following code examples.
C# Code for Windows Forms Viewer |
Copy Code
|
---|---|
var report = new PageReport(…); report.FontResolver = DirectoryFontResolver.Instance; viewer1.LoadDocument(report.Document); |
C# Code for JavaScript Viewer |
Copy Code
|
---|---|
app.UseReportViewer(settings => { settings.UseFontResolver(DirectoryFontResolver.Instance); settings.UseFileStore(ResourcesRootDirectory) }); |
You can configure fonts for preview and export on all platforms without installation as in the following examples.
Copy Code
|
|
---|---|
public sealed class WindowsFontResolver : GrapeCity.ActiveReports.IFontResolver { static readonly GrapeCity.Documents.Text.FontCollection _fonts = new GrapeCity.Documents.Text.FontCollection(); static WindowsFontResolver() { GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateFontLinks(_fonts, true); _fonts.DefaultFont = _fonts.FindFamilyName("Arial"); } public static GrapeCity.ActiveReports.IFontResolver Instance = new WindowsFontResolver(); private WindowsFontResolver() { } GrapeCity.Documents.Text.FontCollection GrapeCity.ActiveReports.IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic) { var fonts = new GrapeCity.Documents.Text.FontCollection(); fonts.Add(_fonts.FindFamilyName(familyName, isBold, isItalic) ?? _fonts.DefaultFont); GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateEudcLinks(fonts); return fonts; } } |
Copy Code
|
|
---|---|
public sealed class DirectoryFontResolver : GrapeCity.ActiveReports.IFontResolver { static readonly GrapeCity.Documents.Text.FontCollection _fonts = new GrapeCity.Documents.Text.FontCollection(); static DirectoryFontResolver() { // see https://developers.redhat.com/blog/2018/11/07/dotnet-special-folder-api-linux/ _fonts.RegisterDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts)); _fonts.DefaultFont = _fonts.FindFamilyName("Arial"); } public static GrapeCity.ActiveReports.IFontResolver Instance = new DirectoryFontResolver(); private DirectoryFontResolver() { } GrapeCity.Documents.Text.FontCollection GrapeCity.ActiveReports.IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic) { var fonts = new GrapeCity.Documents.Text.FontCollection(); var font = _fonts.FindFamilyName(familyName, isBold, isItalic); if (font != null) fonts.Add(font); fonts.Add(_fonts.DefaultFont); return fonts; } } |
See the FontResolver sample for more details.
If you need to link just one font to another (for example, link an EUDC font to an installed font), you can do it with DsPdf and DsImaging APIs, using the following code.
C# Code. PASTE to the beginning of the Main function |
Copy Code
|
---|---|
GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateFontLinks(null, true); var fonts = new System.Collections.Generic.List(); GrapeCity.Documents.Text.FontCollection.SystemFonts.SelectByFamilyName("MS UI Gothic", fonts); if (fonts.Count > 0) { var eudcFonts = new GrapeCity.Documents.Text.FontCollection(); using (var stream = new System.IO.FileStream(@"C:\EudcFonts\DFHSG3J.tte", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) eudcFonts.LoadFonts(stream); foreach (var font in fonts) { font.ClearEudcFontLinks(); foreach (var eudcFont in eudcFonts) font.AddEudcFont(eudcFont); } } |