How to substitute missing font when converting presentations
Background
In case your presentation document contains a font that is not installed into the system GroupDocs.Viewer will use a default font. GroupDocs.Viewer for Java enables you to specify font substitution with setDefaultFontName(…) setting.
Font substitution
To set font substitution for missing fonts please use the following code:
When converting to HTML with embedded resources:
try (Viewer viewer = new Viewer("input.pptx")) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources("output/html_embedded/p_{0}.html");
viewOptions.setDefaultFontName("Times New Roman");
viewer.view(viewOptions);
}
When converting to HTML with external resources:
try (Viewer viewer = new Viewer("input.pptx")) {
HtmlViewOptions viewOptions = HtmlViewOptions.forExternalResources();
viewOptions.setDefaultFontName("Times New Roman");
viewer.view(viewOptions);
}
Output HTML with default font:
Output HTML with “Times New Roman” font:
When converting to PDF:
try (Viewer viewer = new Viewer("input.pptx")) {
PdfViewOptions viewOptions = new PdfViewOptions("output.pdf");
viewOptions.setDefaultFontName("Times New Roman");
viewer.view(viewOptions);
}
Output PDF with default font:
Output PDF with “Times New Roman” font:
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Viewer for Java examples, plugins, and showcase
- Document Viewer for .NET App WebForms UI Modern Example
- Document Viewer for Java App Dropwizard UI Modern Example
- Document Viewer for Java Spring UI Example
- GroupDocs.Viewer for .NET samples, plugins and showcase
- Document Viewer for .NET MVC UI Example
Free Online App
Along with full-featured Java library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.