Exclude fonts

By default, GroupDocs.Viewer embeds the fonts used in the document into HTML. This ensures correct display regardless of the required fonts existing on the viewer device. Depending on the type of HTML rendering, fonts are added as follows:

  • Embedded resources - inline 64-coded fonts
  • External resources - external files

A list of file types that support font embedding is at the end of the page.

Embedding fonts increase the size of the rendered result. To prevent adding fonts that are available on most devices to HTML, add the font names to the getFontsToExclude collection of the HtmlViewOptions class.

The following code snippet shows how to prevent adding the Times New Roman font to HTML.

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.HtmlViewOptions;
// ...

try (Viewer viewer = new Viewer("sample.docx")) {
    HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
    viewOptions.getFontsToExclude().add("Times New Roman");
    viewer.view(viewOptions);
}

List of format families that support adding fonts to HTML

The following source file formats support adding fonts to HTML:

Format NameExtension
Portable Document FormatPDF
Microsoft WordDOC, DOCX, DOCM, DOT, DOTX, DOTM
Microsoft OutlookMSG, EML
Apple MailEMLX
OpenDocument FormatsODT, OTT
Rich Text FormatRTF
Electronic publicationEPUB
Mobipocket e-book formatMOBI
LaTeXTEX
Microsoft PowerPointPPT, PPTX, PPS, PPSX
OpenDocument FormatsODP
Image filesSVG