StreamFontSourceOpenFontDataStream Method

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

Namespace:  Aspose.Words.Fonts
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public abstract Stream OpenFontDataStream()

Return Value

Type: Stream
Font data stream.
Remarks
The stream will be closed after reading. There is no need to close it explicitly.
Examples
Shows how to allows to load fonts from stream.
public void StreamFontSourceFileRendering()
{
    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 + "Font.StreamFontSourceFileRendering.pdf");
}

/// <summary>
/// Load the font data only when it is required and not to store it in the memory for the "FontSettings" lifetime.
/// </summary>
private class StreamFontSourceFile : StreamFontSource
{
    public override Stream OpenFontDataStream()
    {
        return File.OpenRead(FontsDir + "Kreon-Regular.ttf");
    }
}
See Also