Using fonts in reports without installing them

2022-04-27

Using fonts in reports without installing them

The demanding criteria for modern electronic reports are quite high — they must not only display the necessary information, but have a certain design, data format, and graphic content. A modern report is a complex document with design elements. The rapid development of report generators has increased the requirements for documents.

A particular font in a report can be a corporate requirement or a design element. Many report generator users would like to be able to use custom fonts. FastReport.NET allows you to do it! We are talking about TrueTypeFonts.

Now you don’t have to install fonts to use them in the report. You can add them to the report before building. Exporting a report to PDF format allows you to include custom fonts in your document. Let's look at an example of how to add ttf fonts to a report and how to export a report to PDF including these fonts.

//Let’s create a report
Report report = new Report();
//We get the files of the desired fonts from the folder
var fonts = Directory.GetFiles("Fonts");
//Each font is added to the report generator configuration
 foreach (var font in fonts)
 {
 Config.PrivateFontCollection.AddFontFile(font);
}
// Let’s load a report template that contains text objects with set fonts from the Fonts folder
report.Load(@"test.frx");
//Preparing a report
report.Prepare();
//Create an object for exporting to PDF and set the fonts to be included in the document
var export = new PDFExport
 {
 EmbeddingFonts = true
 };
//Let’s export the report
report.Export(export, File.Create(@"test.pdf"));

What’s about the report template? In order to use non-standard fonts when you create a report in the designer, you still need to install them in the system (double click on the ttf font). If you open a report template in a system where there are no fonts used in this template, you will see that the fonts have been replaced with standard ones. However, if you open the template in a text editor, you will see the actual font settings:

<TextObject Name="Text8" Left="359.1" Width="179.55" Height="18.9" 
Text="Roboto-Black.ttf" Font="Roboto Black, 10pt"/>

Thus, if you have a report template with fonts that are not installed in the system, you cannot edit it without losing the font settings, but you can build it and export it if these fonts are added to the FastReport.NET configuration.

Let's say we have a report template created on a system with installed fonts. In the code above, we are adding fonts to the configuration:

Fonts for adding to the configuration

Let's display the report before exporting it to PDF. Let's add a line “report.Show();”.This is what the fonts look like in the report:

Fonts in the finished report

This is what the fonts look like in a PDF document:

Displaying fonts in a PDF document

Thus, if you do not need to develop reports with non-standard fonts, but only display or export them, then you do not need to install these fonts in the system. This can be convenient if you distribute your reports with custom fonts.

November 01, 2024

New Features of the FastReport VCL Editor

We are considering new features of the report editor: extension lines, highlighting of intersecting objects, updated report and data trees.
October 30, 2024

Using Styles When Creating Reports in FastReport VCL

The article discusses one of the new features of FastReport VCL — the use of styles and style sheets.
October 28, 2024

How to Set Up WSL 2 for Working with FastReport and FastCube

In this article, we will explore how to set up WSL 2 for working with FastReport and FastCube components in Lazarus for Linux.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.