FontSavingArgsIsSubsettingNeeded Property

Allows to specify whether the current font will be subsetted before exporting as a font resource.

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public bool IsSubsettingNeeded { get; set; }

Property Value

Type: Boolean
Remarks

Fonts can be exported as complete original font files or subsetted to include only the characters that are used in the document. Subsetting allows to reduce the resulting font resource size.

By default, Aspose.Words decides whether to perform subsetting or not by comparing the original font file size with the one specified in FontResourcesSubsettingSizeThreshold. You can override this behavior for individual fonts by setting the IsSubsettingNeeded property.

Examples
Shows how to define custom logic for handling font exporting when saving to HTML based formats.
public void SaveHtmlExportFonts()
{
    Document doc = new Document(MyDir + "Rendering.docx");

    // Set the option to export font resources
    HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html);
    options.ExportFontResources = true;
    // Create and pass the object which implements the handler methods
    options.FontSavingCallback = new HandleFontSaving();

    doc.Save(ArtifactsDir + "Document.SaveHtmlExportFonts.html", options);
}

/// <summary>
/// Prints information about fonts and saves them alongside their output .html.
/// </summary>
public class HandleFontSaving : IFontSavingCallback
{
    void IFontSavingCallback.FontSaving(FontSavingArgs args)
    {
        // Print information about fonts
        Console.Write($"Font:\t{args.FontFamilyName}");
        if (args.Bold) Console.Write(", bold");
        if (args.Italic) Console.Write(", italic");
        Console.WriteLine($"\nSource:\t{args.OriginalFileName}, {args.OriginalFileSize} bytes\n");

        Assert.True(args.IsExportNeeded);
        Assert.True(args.IsSubsettingNeeded);

        // We can designate where each font will be saved by either specifying a file name, or creating a new stream
        args.FontFileName = args.OriginalFileName.Split(Path.DirectorySeparatorChar).Last();

        args.FontStream = 
            new FileStream(ArtifactsDir + args.OriginalFileName.Split(Path.DirectorySeparatorChar).Last(), FileMode.Create);
        Assert.False(args.KeepFontStreamOpen);

        // We can access the source document from here also
        Assert.True(args.Document.OriginalFileName.EndsWith("Rendering.docx"));
    }
}
See Also