How to get file type and pages count
Introduction
GroupDocs.Viewer for Java API enables you to get file type and pages count with getViewInfo(…) method that returns a ViewInfo object.
For the following document types GroupDocs.Viewer provides additional information:
- Archive files - a collection of folders inside the archive (see How to list archive folders);
- CAD drawings - a collection of layouts and layers (see How to get CAD layers and layouts);
- Outlook Data files - a collection of folders inside Outlook Data file (see How to get Outlook Data file folders);
- PDF documents - a flag that indicates whether document printing is allowed or not (see How to check that PDF printing not allowed);
- MS Project documents - project start/end dates (see How to get MS Project start and end dates).
Get file type and pages count from file
Viewer viewer = new Viewer("sample.pdf");
ViewInfoOptions viewInfoOptions = ViewInfoOptions.forHtmlView();
ViewInfo viewInfo = viewer.getViewInfo(viewInfoOptions);
System.out.println("Document type is: " + viewInfo.getFileType());
System.out.println("Pages count: " + viewInfo.getPages().size());
Get file type and pages count from stream
Viewer viewer = new Viewer(new FileInputStream("sample.pdf"));
ViewInfoOptions viewInfoOptions = ViewInfoOptions.forHtmlView();
ViewInfo viewInfo = viewer.getViewInfo(viewInfoOptions);
System.out.println("Document type is: " + viewInfo.getFileType());
System.out.println("Pages count: " + viewInfo.getPages().size());
More resources
Advanced Usage Topics
To learn more about document viewing features, please refer to the advanced usage section.
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.