Every text in a document has a font. A PDF usually carries its fonts inside the file, while Office documents rely on the fonts installed on the machine that opens them. When a document uses a font that the machine rendering it does not have, GroupDocs.Viewer substitutes another font. If you have the font file, you can give it to GroupDocs.Viewer instead.
How GroupDocs.Viewer substitutes a missing font
A document is often created on one machine and rendered on another, where some of its fonts are missing. GroupDocs.Viewer then picks a substitute by its font substitution rules: it looks at the document’s metadata, the alternative names of the missing font, the settings of the document and the operating system, and the fonts that are installed. On a machine with no fonts at all, it falls back to a font embedded in the GroupDocs.Viewer assembly, for example the free Fanwood font for Word documents.
The substitution happens silently while the document is rendered (when Viewer.View() runs): no message or event tells which font was missing or what replaced it.
Add a font source
If you know that a document uses a font that is not installed on the target machine, and you have the font file, add a font source before you call Viewer.View(). A font source is a folder with one or more fonts, represented by the FolderFontSource class. The FontSettings.SetFontSources() method adds font sources to GroupDocs.Viewer.
The following code snippet demonstrates this. The presentation harvest-launch.pptx sets its text in Lobster, a font that most machines do not have and that the file does not embed. The font file, Lobster-Regular.ttf, is in the custom_fonts folder next to the code. An instance of the FolderFontSource class points to this folder and is passed to the FontSettings static class, and then the presentation is rendered to HTML. As a result, the output HTML uses Lobster; without the font source, GroupDocs.Viewer would substitute another font.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;usingGroupDocs.Viewer.Fonts;// ...// Specify the font source: the custom_fonts folder holds Lobster-Regular.ttf.// SearchOption is named in full: System.IO, which .NET 6+ projects import by default, has one too.FolderFontSourcefontSource=newFolderFontSource("custom_fonts",GroupDocs.Viewer.Fonts.SearchOption.TopFolderOnly);FontSettings.SetFontSources(fontSource);using(Viewerviewer=newViewer("harvest-launch.pptx")){// Create an HTML file.HtmlViewOptionsviewOptions=HtmlViewOptions.ForEmbeddedResources();viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.OptionsImportsGroupDocs.Viewer.Fonts' ...
ModuleProgramSubMain(argsAsString())' Specify the font source: the custom_fonts folder holds Lobster-Regular.ttf.
DimfontSourceAsFolderFontSource=NewFolderFontSource("custom_fonts",GroupDocs.Viewer.Fonts.SearchOption.TopFolderOnly)FontSettings.SetFontSources(fontSource)UsingviewerAsViewer=NewViewer("harvest-launch.pptx")' Create an HTML file.
DimviewOptionsAsHtmlViewOptions=HtmlViewOptions.ForEmbeddedResources()viewer.View(viewOptions)EndUsingEndSubEndModule
harvest-launch.pptx is the sample file used in this example. Click here to download it.
Lobster-Regular.ttf is the font the example loads from the custom_fonts folder. Click here to download it. Lobster is by The Lobster Project Authors and is licensed under the SIL Open Font License 1.1.
Without the font file, you can still choose the font that replaces the missing one, instead of leaving the choice to the substitution rules. See Replace missing font.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Ask AI
Ask anything about this page — the answer is based on its content.
Searching the docs and writing an answer…
Something went wrong while getting an answer. Please try again in a moment.