Specify file type when loading a document

When passing file path or InputStream into Viewer class constructor the GroupDocs.Viewer determines file type by file extension but when file passed as InputStream the GroupDocs.Viewer for Java tries to detect file type by file signature or file content and this may affect application performance. The API enables you to specify the file type of the processing document by passing LoadOptions  object as the second parameter of Viewer class constructor. When you’re passing file type it instructs GroupDocs.Viewer to skip file type detection feature and proceed with rendering.

The following code sample shows how to pass the file type when loading a document.

   LoadOptions loadOptions = new LoadOptions(FileType.DOCX);

   try (Viewer viewer = new Viewer(new FileInputStream("sample.docx"), loadOptions)) {
       HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();

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.