StreamFontSource Class

Base class for user-defined stream font source.

Inheritance Hierarchy

Namespace:  Aspose.Words.Fonts
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public abstract class StreamFontSource : FontSourceBase

The StreamFontSource type exposes the following members.


Public propertyCode examplePriority
Returns the font source priority.
(Inherited from FontSourceBase.)
Public propertyType
Returns the type of the font source.
(Overrides FontSourceBaseType.)


Public methodEquals (Inherited from Object.)
Public methodCode exampleGetAvailableFonts
Returns list of fonts available via this source.
(Inherited from FontSourceBase.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleOpenFontDataStream
This method should open the stream with font data on demand.
Public methodToString (Inherited from Object.)


In order to use the stream font source you should create a derived class from the StreamFontSource and provide implementation of the OpenFontDataStream method.

OpenFontDataStream method could be called several times. For the first time it will be called when Aspose.Words scans the provided font sources to get the list of available fonts. Later it may be called if the font is used in the document to parse the font data and to embed the font data to some output formats.

StreamFontSource may be useful because it allows to load the font data only when it is required and not to store it in the memory for the FontSettings lifetime.


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