DefaultFontSubstitutionRule Class

Default font substitution rule.

Inheritance Hierarchy


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


public class DefaultFontSubstitutionRule : FontSubstitutionRule

The DefaultFontSubstitutionRule type exposes the following members.


Public propertyCode exampleDefaultFontName
Gets or sets the default font name.
Public propertyCode exampleEnabled
Specifies whether the rule is enabled or not.
(Inherited from FontSubstitutionRule.)


Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)


This rule defines single default font name to be used for substitution if the original font is not available.


Shows how to set the default font substitution rule.
// Create a blank document and a new FontSettings property
Document doc = new Document();
FontSettings fontSettings = new FontSettings();
doc.FontSettings = fontSettings;

// Get the default substitution rule within FontSettings, which will be enabled by default and will substitute all missing fonts with "Times New Roman"
DefaultFontSubstitutionRule defaultFontSubstitutionRule = fontSettings.SubstitutionSettings.DefaultFontSubstitution;
Assert.AreEqual("Times New Roman", defaultFontSubstitutionRule.DefaultFontName);

// Set the default font substitute to "Courier New"
defaultFontSubstitutionRule.DefaultFontName = "Courier New";

// Using a document builder, add some text in a font that we don't have to see the substitution take place,
// and render the result in a PDF
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Font.Name = "Missing Font";
builder.Writeln("Line written in a missing font, which will be substituted with Courier New.");

doc.Save(ArtifactsDir + "Font.DefaultFontSubstitutionRule.pdf");

See Also