Specify file type when loading a document
When passing file path 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); Viewer viewer = new Viewer(new FileInputStream("sample.docx"), loadOptions); HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(); viewer.view(viewOptions); viewer.close();
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.