Get file info

GroupDocs.Comparison allows you to get the following file information:

  • FileType represents the document file type (PDF, Word document, Excel spreadsheet, PowerPoint presentation or image etc.).
  • PageCount represents count of document pages.
  • FileSize represents the document file size.
  • PagesInfo represents the page information.

The following code samples show how to get file information:

Get file info for the file from local disk


try (Comparer comparer = new Comparer(sourceFile)) {
    IDocumentInfo info = comparer.getSource().getDocumentInfo();
    for (int i = 0; i < info.getPageCount(); i++) {
        System.out.printf("\nFile type: %s\nNumber of pages: %d\nDocument size: %d bytes\nWidth: %d\nHeight: %d%n",
            info.getFileType().getFileFormat(), info.getPageCount(), info.getSize(), info.getPagesInfo().get(i).getWidth(), info.getPagesInfo().get(i).getHeight());
    }
}

The result is as follows:

Get file info for the file from stream


try (InputStream inputStream = new FileInputStream(sourceFile);
    Comparer comparer = new Comparer(inputStream)) {
    IDocumentInfo info = comparer.getSource().getDocumentInfo();
    for (int i = 0; i < info.getPageCount(); i++) {
        System.out.printf("\nFile type: %s\nNumber of pages: %d\nDocument size: %d bytes\nWidth: %d\nHeight: %d%n", 
            info.getFileType().getFileFormat(), info.getPageCount(), info.getSize(), info.getPagesInfo().get(i).getWidth(), info.getPagesInfo().get(i).getHeight());
    }
}