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:

    Viewer viewer = new Viewer("input.pptx");
    HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources("output/html_embedded/p_{0}.html");
    viewOptions.setDefaultFontName("Times New Roman");
    viewer.view(viewOptions);
    viewer.close();

When converting to HTML with external resources:

    Viewer viewer = new Viewer("input.pptx");
    HtmlViewOptions viewOptions = HtmlViewOptions.forExternalResources();
    viewOptions.setDefaultFontName("Times New Roman");
    viewer.view(viewOptions);
    viewer.close();

Output HTML with default font:

Output HTML with “Times New Roman” font:

When converting to PDF:

    Viewer viewer = new Viewer("input.pptx");
    PdfViewOptions viewOptions = new PdfViewOptions("output.pdf");
    viewOptions.setDefaultFontName("Times New Roman");
    viewer.view(viewOptions);
    viewer.close();

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:

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.