StreamFontSource.OpenFontDataStream method

This method should open the stream with font data on demand.

public abstract Stream OpenFontDataStream()

Return Value

Font data stream.


The stream will be closed after reading. There is no need to close it explicitly.


Shows how to load fonts from stream.

    FontSettings fontSettings = new FontSettings();
    fontSettings.SetFontsSources(new FontSourceBase[] {new StreamFontSourceFile()});

    DocumentBuilder builder = new DocumentBuilder();
    builder.Document.FontSettings = fontSettings;
    builder.Font.Name = "Kreon-Regular";
    builder.Writeln("Test aspose text when saving to PDF.");

    builder.Document.Save(ArtifactsDir + "FontSettings.StreamFontSourceFileRendering.pdf");

/// <summary>
/// Load the font data only when required instead of storing it in the memory
/// for the entire lifetime of the "FontSettings" object.
/// </summary>
private class StreamFontSourceFile : StreamFontSource
    public override Stream OpenFontDataStream()
        return File.OpenRead(FontsDir + "Kreon-Regular.ttf");

See Also