HtmlFixedSaveOptionsFontFormat Property

Gets or sets ExportFontFormat used for font exporting. Default value is Woff.

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.10.0

ExpandedSyntax

public ExportFontFormat FontFormat { get; set; }

Property Value

Type: ExportFontFormat

ExpandedExamples

Shows how use target machine fonts to display the document.
public void UsingMachineFonts()
{
    Document doc = new Document(MyDir + "Bullet points with alternative font.docx");

    HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions
    {
        ExportEmbeddedCss = true,
        UseTargetMachineFonts = true,
        FontFormat = ExportFontFormat.Ttf,
        ExportEmbeddedFonts = false,
        ResourceSavingCallback = new ResourceSavingCallback()
    };

    doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.UsingMachineFonts.html", saveOptions);

    string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.UsingMachineFonts.html");

    if (saveOptions.UseTargetMachineFonts)
        Assert.False(Regex.Match(outDocContents, "@font-face").Success);
    else
        Assert.True(Regex.Match(outDocContents,
            "@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], " +
            "url[(]'HtmlFixedSaveOptions.UsingMachineFonts/font001.ttf'[)] format[(]'truetype'[)]; }").Success);
}

private class ResourceSavingCallback : IResourceSavingCallback
{
    /// <summary>
    /// Called when Aspose.Words saves an external resource to fixed page HTML or SVG.
    /// </summary>
    public void ResourceSaving(ResourceSavingArgs args)
    {
        Console.WriteLine($"Original document URI:\t{args.Document.OriginalFileName}");
        Console.WriteLine($"Resource being saved:\t{args.ResourceFileName}");
        Console.WriteLine($"Full uri after saving:\t{args.ResourceFileUri}");

        args.ResourceStream = new MemoryStream();
        args.KeepResourceStreamOpen = true;

        string extension = Path.GetExtension(args.ResourceFileName);
        switch (extension)
        {
            case ".ttf":
            case ".woff":
            {
                Assert.Fail("'ResourceSavingCallback' is not fired for fonts when 'UseTargetMachineFonts' is true");
                break;
            }
        }
    }
}

ExpandedSee Also