FontSavingArgs Class

Provides data for the FontSaving(FontSavingArgs) event.
Inheritance Hierarchy
SystemObject
  Aspose.Words.SavingFontSavingArgs

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class FontSavingArgs

The FontSavingArgs type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleBold
Indicates whether the current font is bold.
Public propertyCode exampleDocument
Gets the document object that is being saved.
Public propertyCode exampleFontFamilyName
Indicates the current font family name.
Public propertyCode exampleFontFileName
Gets or sets the file name (without path) where the font will be saved to.
Public propertyCode exampleFontStream
Allows to specify the stream where the font will be saved to.
Public propertyCode exampleIsExportNeeded
Allows to specify whether the current font will be exported as a font resource. Default is true.
Public propertyCode exampleIsSubsettingNeeded
Allows to specify whether the current font will be subsetted before exporting as a font resource.
Public propertyCode exampleItalic
Indicates whether the current font is italic.
Public propertyCode exampleKeepFontStreamOpen
Specifies whether Aspose.Words should keep the stream open or close it after saving a font.
Public propertyCode exampleOriginalFileName
Gets the original font file name with an extension.
Public propertyCode exampleOriginalFileSize
Gets the original font file size.
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)
Remarks

When Aspose.Words saves a document to HTML or related formats and ExportFontResources is set to true, it saves each font subject for export into a separate file.

FontSavingArgs controls whether particular font resource should be exported and how.

FontSavingArgs also allows to redefine how font file names are generated or to completely circumvent saving of fonts into files by providing your own stream objects.

To decide whether to save a particular font resource, use the IsExportNeeded property.

To save fonts into streams instead of files, use the FontStream 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