FontSettings

LoadOptions.FontSettings property

Allows to specify document font settings.

public FontSettings FontSettings { get; set; }

Remarks

When loading some formats, Aspose.Words may require to resolve the fonts. For example, when loading HTML documents Aspose.Words may resolve the fonts to perform font fallback.

If set to null, default static font settings DefaultInstance will be used.

The default value is null.

Examples

Shows how to apply font substitution settings while loading a document.

// Create a FontSettings object that will substitute the "Times New Roman" font
// with the font "Arvo" from our "MyFonts" folder.
FontSettings fontSettings = new FontSettings();
fontSettings.SetFontsFolder(FontsDir, false);
fontSettings.SubstitutionSettings.TableSubstitution.AddSubstitutes("Times New Roman", "Arvo");

// Set that FontSettings object as a property of a newly created LoadOptions object.
LoadOptions loadOptions = new LoadOptions();
loadOptions.FontSettings = fontSettings;

// Load the document, then render it as a PDF with the font substitution.
Document doc = new Document(MyDir + "Document.docx", loadOptions);

doc.Save(ArtifactsDir + "LoadOptions.FontSettings.pdf");

Shows how to designate font substitutes during loading.

LoadOptions loadOptions = new LoadOptions();
loadOptions.FontSettings = new FontSettings();

// Set a font substitution rule for a LoadOptions object.
// If the document we are loading uses a font which we do not have,
// this rule will substitute the unavailable font with one that does exist.
// In this case, all uses of the "MissingFont" will convert to "Comic Sans MS".
TableSubstitutionRule substitutionRule = loadOptions.FontSettings.SubstitutionSettings.TableSubstitution;
substitutionRule.AddSubstitutes("MissingFont", new[] {"Comic Sans MS"});

Document doc = new Document(MyDir + "Missing font.html", loadOptions);

// At this point such text will still be in "MissingFont".
// Font substitution will take place when we render the document.
Assert.AreEqual("MissingFont", doc.FirstSection.Body.FirstParagraph.Runs[0].Font.Name);

doc.Save(ArtifactsDir + "FontSettings.ResolveFontsBeforeLoadingDocument.pdf");

See Also