How to get file type and pages count

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:

Loading document from file

try (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());
}

After running the code above you will see an output like this:

Document type is: Portable Document Format File (.pdf)
Pages count: 10

Loading document from stream

FileInputStream inputStream = new FileInputStream("sample.pdf");
LoadOptions loadOptions = new LoadOptions(FileType.PDF);

try (Viewer viewer = new Viewer(inputStream, loadOptions)) {
    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());
}

After running the code above you will see an output like this:

Document type is: Portable Document Format File (.pdf)
Pages count: 10