Adding a Font to the Resource
Our sample projects and report templates can help you learn the basics of working with our products.Fonts can be embedded into a report as resources so the document renders and exports identically regardless of the fonts installed on the server.
Embedding the font. In the report action, read the font file, add it as a
Using the font. Create the font from the collection and assign it to a component:
Because the font travels inside the report, server-side exports such as PDF are pixel-perfect even on machines where the font is not installed — important for web applications running on servers with a minimal font set.
Embedding the font. In the report action, read the font file, add it as a
StiResource, and register it in the font collection:var fileContent = System.IO.File.ReadAllBytes(StiNetCoreHelper.MapPath(this, "Fonts/Roboto-Black.ttf"));
var resource = new StiResource("Roboto-Black", "Roboto-Black", false, StiResourceType.FontTtf, fileContent, false);
report.Dictionary.Resources.Add(resource);
StiFontCollection.AddResourceFont(resource.Name, resource.Content, "ttf", resource.Alias);Using the font. Create the font from the collection and assign it to a component:
var dataText = new StiText();
dataText.ClientRectangle = new RectangleD(1, 1, 3, 2);
dataText.Text = "Sample Text";
dataText.Font = StiFontCollection.CreateFont("Roboto-Black", 12, FontStyle.Regular);
report.Pages[0].Components.Add(dataText);Because the font travels inside the report, server-side exports such as PDF are pixel-perfect even on machines where the font is not installed — important for web applications running on servers with a minimal font set.