By default, GroupDocs.Viewer includes (exports) the fonts used in the loaded document into the produced HTML. This ensures correct display regardless of the required fonts existing on the viewer device. Depending on the type of HTML rendering, fonts are included as follows:
Embedded resources — font content is embedded (inlined, backed) directly inside the HTML-markup using the data URI scheme through base64 encoding.
External resources — font content is stored aside from the HTML document, externally; each font may be stored as a distinct file on the disk or its content may be written to the byte stream, specified by the user through a CreateResourceStream delegate.
GroupDocs.Viewer supports a lot of document formats, and not for all of them it is possible to export the fonts to the resultant produced HTML. A list of file formats that support font export when rendering them to HTML format is provided in the list below:
Portable Document Format (PDF)
Microsoft Word formats (DOC, DOCX, DOCM, DOT, DOTX, DOTM)
Microsoft PowerPoint formats (PPT, PPTX, PPS, PPSX)
Sometimes including fonts to the produced HTML document is unwanted: for example, user masy have all the font installed on the operating system, where the HTML document should be viewed, and browser can use system-installed fonts. Also when fonts are included, they significantly increase the size of the produced HTML document. To prevent adding fonts that are available on most devices to produced HTML, the GroupDocs.Viewer provides two options: exclude all fonts (complete fonts exclusion) and exclude specified fonts only (selective fonts exclusion).
Both these options are represented in the HtmlViewOptions class as different properties:
ExcludeFonts is a flag that disables export of all used fonts to the produced HTML document, when enabled (true). By default this option is disabled (false).
FontsToExclude is a list of string, each one represents one font name, that should be excluded from the produced HTML document. By default this list is empty — no fonts are excluded. Please note that this options works only if the ExcludeFonts property is disabled (false).
The folowing code snippet shows how to exclude all fonts from the produced HTML document with the ExcludeFonts flag.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(Viewerviewer=newViewer("sample.docx")){// Create an HTML file.varviewOptions=HtmlViewOptions.ForEmbeddedResources();viewOptions.ExcludeFonts=true;viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())UsingviewerAsViewer=NewViewer("sample.docx")' Create an HTML file.
DimviewOptions=HtmlViewOptions.ForEmbeddedResources()viewOptions.ExcludeFonts=Trueviewer.View(viewOptions)EndUsingEndSubEndModule
The following code snippet demonstrates the work of the FontsToExclude property — it shows how to prevent adding the Times New Roman and Arial fonts to HTML.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(Viewerviewer=newViewer("sample.docx")){// Create an HTML file.varviewOptions=HtmlViewOptions.ForEmbeddedResources();viewOptions.FontsToExclude.Add("Times New Roman");// Exclude the Times New Roman font.viewOptions.FontsToExclude.Add("Arial");// Exclude the Arial font.viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())UsingviewerAsViewer=NewViewer("sample.docx")' Create an HTML file.
DimviewOptions=HtmlViewOptions.ForEmbeddedResources()viewOptions.FontsToExclude.Add("Times New Roman")' Exclude the Times New Roman font.
viewOptions.FontsToExclude.Add("Arial")' Exclude the Arial font.
viewer.View(viewOptions)EndUsingEndSubEndModule
Supported formats for exclusion
Need to mention that not all formats, listed above, support the complete and selective font exclusion. Two lists below show which formats are supported:
Complete fonts exclusion using ExcludeFonts:
All Microsoft Word formats (DOX, DOCX, DOCM, …)